/* this file has been autogenerated by vtkNodeJsWrap */
/* editing this might proof futile */

#define VTK_WRAPPING_CXX
#define VTK_STREAMS_FWD_ONLY
#include <nan.h>

#include "vtkPointSetAlgorithmWrap.h"
#include "vtkCenterOfMassWrap.h"
#include "vtkObjectWrap.h"
#include "vtkPointsWrap.h"
#include "vtkDataArrayWrap.h"
#include "../../plus/plus.h"

using namespace v8;

extern Nan::Persistent<v8::Object> vtkNodeJsNoWrap;
Nan::Persistent<v8::FunctionTemplate> VtkCenterOfMassWrap::ptpl;

VtkCenterOfMassWrap::VtkCenterOfMassWrap()
{ }

VtkCenterOfMassWrap::VtkCenterOfMassWrap(vtkSmartPointer<vtkCenterOfMass> _native)
{ native = _native; }

VtkCenterOfMassWrap::~VtkCenterOfMassWrap()
{ }

void VtkCenterOfMassWrap::Init(v8::Local<v8::Object> exports)
{
	Nan::SetAccessor(exports, Nan::New("vtkCenterOfMass").ToLocalChecked(), ConstructorGetter);
	Nan::SetAccessor(exports, Nan::New("CenterOfMass").ToLocalChecked(), ConstructorGetter);
}

void VtkCenterOfMassWrap::ConstructorGetter(
	v8::Local<v8::String> property,
	const Nan::PropertyCallbackInfo<v8::Value>& info)
{
	InitPtpl();
	info.GetReturnValue().Set(Nan::New(ptpl)->GetFunction());
}

void VtkCenterOfMassWrap::InitPtpl()
{
	if (!ptpl.IsEmpty()) return;
	v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
	VtkPointSetAlgorithmWrap::InitPtpl( );
	tpl->Inherit(Nan::New<FunctionTemplate>(VtkPointSetAlgorithmWrap::ptpl));
	tpl->SetClassName(Nan::New("VtkCenterOfMassWrap").ToLocalChecked());
	tpl->InstanceTemplate()->SetInternalFieldCount(1);

	Nan::SetPrototypeMethod(tpl, "ComputeCenterOfMass", ComputeCenterOfMass);
	Nan::SetPrototypeMethod(tpl, "computeCenterOfMass", ComputeCenterOfMass);

	Nan::SetPrototypeMethod(tpl, "GetCenter", GetCenter);
	Nan::SetPrototypeMethod(tpl, "getCenter", GetCenter);

	Nan::SetPrototypeMethod(tpl, "GetClassName", GetClassName);
	Nan::SetPrototypeMethod(tpl, "getClassName", GetClassName);

	Nan::SetPrototypeMethod(tpl, "GetUseScalarsAsWeights", GetUseScalarsAsWeights);
	Nan::SetPrototypeMethod(tpl, "getUseScalarsAsWeights", GetUseScalarsAsWeights);

	Nan::SetPrototypeMethod(tpl, "IsA", IsA);
	Nan::SetPrototypeMethod(tpl, "isA", IsA);

	Nan::SetPrototypeMethod(tpl, "NewInstance", NewInstance);
	Nan::SetPrototypeMethod(tpl, "newInstance", NewInstance);

	Nan::SetPrototypeMethod(tpl, "SafeDownCast", SafeDownCast);
	Nan::SetPrototypeMethod(tpl, "safeDownCast", SafeDownCast);

	Nan::SetPrototypeMethod(tpl, "SetCenter", SetCenter);
	Nan::SetPrototypeMethod(tpl, "setCenter", SetCenter);

	Nan::SetPrototypeMethod(tpl, "SetUseScalarsAsWeights", SetUseScalarsAsWeights);
	Nan::SetPrototypeMethod(tpl, "setUseScalarsAsWeights", SetUseScalarsAsWeights);

#ifdef VTK_NODE_PLUS_VTKCENTEROFMASSWRAP_INITPTPL
	VTK_NODE_PLUS_VTKCENTEROFMASSWRAP_INITPTPL
#endif
	ptpl.Reset( tpl );
}

void VtkCenterOfMassWrap::New(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	if(!info.IsConstructCall())
	{
		Nan::ThrowError("Constructor not called in a construct call.");
		return;
	}

	if(info.Length() == 0)
	{
		vtkSmartPointer<vtkCenterOfMass> native = vtkSmartPointer<vtkCenterOfMass>::New();
		VtkCenterOfMassWrap* obj = new VtkCenterOfMassWrap(native);
		obj->Wrap(info.This());
	}
	else
	{
		if(info[0]->ToObject() != vtkNodeJsNoWrap )
		{
			Nan::ThrowError("Parameter Error");
			return;
		}
	}

	info.GetReturnValue().Set(info.This());
}

void VtkCenterOfMassWrap::ComputeCenterOfMass(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	VtkCenterOfMassWrap *wrapper = ObjectWrap::Unwrap<VtkCenterOfMassWrap>(info.Holder());
	vtkCenterOfMass *native = (vtkCenterOfMass *)wrapper->native.GetPointer();
	size_t i;
	if(info.Length() > 0 && info[0]->IsObject() && (Nan::New(VtkPointsWrap::ptpl))->HasInstance(info[0]))
	{
		VtkPointsWrap *a0 = ObjectWrap::Unwrap<VtkPointsWrap>(info[0]->ToObject());
		if(info.Length() > 1 && info[1]->IsObject() && (Nan::New(VtkDataArrayWrap::ptpl))->HasInstance(info[1]))
		{
			VtkDataArrayWrap *a1 = ObjectWrap::Unwrap<VtkDataArrayWrap>(info[1]->ToObject());
			if(info.Length() > 2 && info[2]->IsFloat64Array())
			{
				v8::Local<v8::Float64Array>a2(v8::Local<v8::Float64Array>::Cast(info[2]->ToObject()));
				if( a2->Length() < 3 )
				{
					Nan::ThrowError("Array too short.");
					return;
				}

								if(info.Length() != 3)
				{
					Nan::ThrowError("Too many parameters.");
					return;
				}
				native->ComputeCenterOfMass(
					(vtkPoints *) a0->native.GetPointer(),
					(vtkDataArray *) a1->native.GetPointer(),
					(double *)(a2->Buffer()->GetContents().Data())
				);
				return;
			}
			else if(info.Length() > 2 && info[2]->IsArray())
			{
				v8::Local<v8::Array>a2(v8::Local<v8::Array>::Cast(info[2]->ToObject()));
				double b2[3];
				if( a2->Length() < 3 )
				{
					Nan::ThrowError("Array too short.");
					return;
				}

				for( i = 0; i < 3; i++ )
				{
					if( !a2->Get(i)->IsNumber() )
					{
						Nan::ThrowError("Array contents invalid.");
						return;
					}
					b2[i] = a2->Get(i)->NumberValue();
				}
								if(info.Length() != 3)
				{
					Nan::ThrowError("Too many parameters.");
					return;
				}
				native->ComputeCenterOfMass(
					(vtkPoints *) a0->native.GetPointer(),
					(vtkDataArray *) a1->native.GetPointer(),
					b2
				);
				return;
			}
		}
	}
	Nan::ThrowError("Parameter mismatch");
}

void VtkCenterOfMassWrap::GetCenter(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	VtkCenterOfMassWrap *wrapper = ObjectWrap::Unwrap<VtkCenterOfMassWrap>(info.Holder());
	vtkCenterOfMass *native = (vtkCenterOfMass *)wrapper->native.GetPointer();
	double const * r;
	if(info.Length() != 0)
	{
		Nan::ThrowError("Too many parameters.");
		return;
	}
	r = native->GetCenter();
	Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), 3 * sizeof(double));
	Local<v8::Float64Array> at = v8::Float64Array::New(ab, 0, 3);
	memcpy(ab->GetContents().Data(), r, 3 * sizeof(double));
	info.GetReturnValue().Set(at);
}

void VtkCenterOfMassWrap::GetClassName(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	VtkCenterOfMassWrap *wrapper = ObjectWrap::Unwrap<VtkCenterOfMassWrap>(info.Holder());
	vtkCenterOfMass *native = (vtkCenterOfMass *)wrapper->native.GetPointer();
	char const * r;
	if(info.Length() != 0)
	{
		Nan::ThrowError("Too many parameters.");
		return;
	}
	r = native->GetClassName();
	info.GetReturnValue().Set(Nan::New(r).ToLocalChecked());
}

void VtkCenterOfMassWrap::GetUseScalarsAsWeights(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	VtkCenterOfMassWrap *wrapper = ObjectWrap::Unwrap<VtkCenterOfMassWrap>(info.Holder());
	vtkCenterOfMass *native = (vtkCenterOfMass *)wrapper->native.GetPointer();
	bool r;
	if(info.Length() != 0)
	{
		Nan::ThrowError("Too many parameters.");
		return;
	}
	r = native->GetUseScalarsAsWeights();
	info.GetReturnValue().Set(Nan::New(r));
}

void VtkCenterOfMassWrap::IsA(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	VtkCenterOfMassWrap *wrapper = ObjectWrap::Unwrap<VtkCenterOfMassWrap>(info.Holder());
	vtkCenterOfMass *native = (vtkCenterOfMass *)wrapper->native.GetPointer();
	if(info.Length() > 0 && info[0]->IsString())
	{
		Nan::Utf8String a0(info[0]);
		int r;
		if(info.Length() != 1)
		{
			Nan::ThrowError("Too many parameters.");
			return;
		}
		r = native->IsA(
			*a0
		);
		info.GetReturnValue().Set(Nan::New(r));
		return;
	}
	Nan::ThrowError("Parameter mismatch");
}

void VtkCenterOfMassWrap::NewInstance(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	VtkCenterOfMassWrap *wrapper = ObjectWrap::Unwrap<VtkCenterOfMassWrap>(info.Holder());
	vtkCenterOfMass *native = (vtkCenterOfMass *)wrapper->native.GetPointer();
	vtkCenterOfMass * r;
	if(info.Length() != 0)
	{
		Nan::ThrowError("Too many parameters.");
		return;
	}
	r = native->NewInstance();
	VtkCenterOfMassWrap::InitPtpl();
	v8::Local<v8::Value> argv[1] =
		{ Nan::New(vtkNodeJsNoWrap) };
	v8::Local<v8::Function> cons =
		Nan::New<v8::FunctionTemplate>(VtkCenterOfMassWrap::ptpl)->GetFunction();
	v8::Local<v8::Object> wo = cons->NewInstance(1, argv);
	VtkCenterOfMassWrap *w = new VtkCenterOfMassWrap();
	w->native = r;
	w->Wrap(wo);
	info.GetReturnValue().Set(wo);
}

void VtkCenterOfMassWrap::SafeDownCast(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	VtkCenterOfMassWrap *wrapper = ObjectWrap::Unwrap<VtkCenterOfMassWrap>(info.Holder());
	vtkCenterOfMass *native = (vtkCenterOfMass *)wrapper->native.GetPointer();
	if(info.Length() > 0 && info[0]->IsObject() && (Nan::New(VtkObjectWrap::ptpl))->HasInstance(info[0]))
	{
		VtkObjectWrap *a0 = ObjectWrap::Unwrap<VtkObjectWrap>(info[0]->ToObject());
		vtkCenterOfMass * r;
		if(info.Length() != 1)
		{
			Nan::ThrowError("Too many parameters.");
			return;
		}
		r = native->SafeDownCast(
			(vtkObject *) a0->native.GetPointer()
		);
		VtkCenterOfMassWrap::InitPtpl();
		v8::Local<v8::Value> argv[1] =
			{ Nan::New(vtkNodeJsNoWrap) };
		v8::Local<v8::Function> cons =
			Nan::New<v8::FunctionTemplate>(VtkCenterOfMassWrap::ptpl)->GetFunction();
		v8::Local<v8::Object> wo = cons->NewInstance(1, argv);
		VtkCenterOfMassWrap *w = new VtkCenterOfMassWrap();
		w->native = r;
		w->Wrap(wo);
		info.GetReturnValue().Set(wo);
		return;
	}
	Nan::ThrowError("Parameter mismatch");
}

void VtkCenterOfMassWrap::SetCenter(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	VtkCenterOfMassWrap *wrapper = ObjectWrap::Unwrap<VtkCenterOfMassWrap>(info.Holder());
	vtkCenterOfMass *native = (vtkCenterOfMass *)wrapper->native.GetPointer();
	size_t i;
	if(info.Length() > 0 && info[0]->IsFloat64Array())
	{
		v8::Local<v8::Float64Array>a0(v8::Local<v8::Float64Array>::Cast(info[0]->ToObject()));
		if( a0->Length() < 3 )
		{
			Nan::ThrowError("Array too short.");
			return;
		}

				if(info.Length() != 1)
		{
			Nan::ThrowError("Too many parameters.");
			return;
		}
		native->SetCenter(
			(double *)(a0->Buffer()->GetContents().Data())
		);
		return;
	}
	else if(info.Length() > 0 && info[0]->IsArray())
	{
		v8::Local<v8::Array>a0(v8::Local<v8::Array>::Cast(info[0]->ToObject()));
		double b0[3];
		if( a0->Length() < 3 )
		{
			Nan::ThrowError("Array too short.");
			return;
		}

		for( i = 0; i < 3; i++ )
		{
			if( !a0->Get(i)->IsNumber() )
			{
				Nan::ThrowError("Array contents invalid.");
				return;
			}
			b0[i] = a0->Get(i)->NumberValue();
		}
				if(info.Length() != 1)
		{
			Nan::ThrowError("Too many parameters.");
			return;
		}
		native->SetCenter(
			b0
		);
		return;
	}
	else if(info.Length() > 0 && info[0]->IsNumber())
	{
		if(info.Length() > 1 && info[1]->IsNumber())
		{
			if(info.Length() > 2 && info[2]->IsNumber())
			{
								if(info.Length() != 3)
				{
					Nan::ThrowError("Too many parameters.");
					return;
				}
				native->SetCenter(
					info[0]->NumberValue(),
					info[1]->NumberValue(),
					info[2]->NumberValue()
				);
				return;
			}
		}
	}
	Nan::ThrowError("Parameter mismatch");
}

void VtkCenterOfMassWrap::SetUseScalarsAsWeights(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
	VtkCenterOfMassWrap *wrapper = ObjectWrap::Unwrap<VtkCenterOfMassWrap>(info.Holder());
	vtkCenterOfMass *native = (vtkCenterOfMass *)wrapper->native.GetPointer();
	if(info.Length() > 0 && info[0]->IsBoolean())
	{
				if(info.Length() != 1)
		{
			Nan::ThrowError("Too many parameters.");
			return;
		}
		native->SetUseScalarsAsWeights(
			info[0]->BooleanValue()
		);
		return;
	}
	Nan::ThrowError("Parameter mismatch");
}

