示例#1
0
文件: p2.cpp 项目: igorpejic/graphics
vtkSmartPointer<vtkStructuredGrid> createGrid(const int& dimx, const int& dimy)
{
    VTK_CREATE(vtkStructuredGrid, grid);
    VTK_CREATE(vtkPoints, points);


    // TODO
    double x0{0.}, y0{0.}, x1{3.14}, y1{2.};
    double x{x0}, y{y0};
    // donja linija y(x) = sin(x)
    // gornja linija: y(x) = y1

    for(unsigned int j = 0; j < dimy; j++)
    {
        y += 1.0;
        for(unsigned int i = 0; i < dimx; i++)
        {
            //x += .5;
            //points->InsertNextPoint(x, y,0);
		double dx = (x1-x0)/dimx;
		x = x0+i*dx;
		y0 = sin(x);
		double dy = (y1-sin(x))/dimy;
		y = y0+j*dy;
	        points->InsertNextPoint(x, y,0);
        }
    }
    grid->SetDimensions(dimx,dimy,1);
    grid->SetPoints(points);
    return grid;
}
示例#2
0
PointPlotter::PointPlotter()
{
    pts = vtkPoints::New();
    //pts->Allocate(30);
    //pts->SetNumberOfPoints(30);
    //pts->SetNumberOfPoints(MAX_POINTS);
    SetPointRadius(2);
    SetPointResolution();

    scalars = vtkUnsignedCharArray::New();
    scalars->SetNumberOfComponents(3);
    colors=vtkFloatArray::New();

//	VTK_CREATE(vtkDiskSource,src);
//	src->SetRadialResolution(5);
//	src->SetCircumferentialResolution(pt_res);
//	src->SetInnerRadius(0.00);
//	src->SetOuterRadius(pt_radius);

    VTK_CREATE(vtkRegularPolygonSource,src);
    src->SetRadius(2.0);
    src->SetNumberOfSides(5);


    VTK_CREATE(vtkPolyData,polyData);
    polyData->SetPoints(pts);
    //polyData->GetPointData()->SetScalars(scalars);
    polyData->GetPointData()->SetScalars(colors);

    VTK_CREATE(vtkGlyph3D,glyph);
    glyph->SetSourceConnection(src->GetOutputPort());

#if VTK_MAJOR_VERSION <= 5
    glyph->SetInput(polyData);
#else
    glyph->SetInputData(polyData);
#endif

    glyph->SetColorModeToColorByScalar();
    glyph->SetScaleModeToDataScalingOff() ;


    VTK_CREATE(vtkPolyDataMapper,mapper);
    mapper->SetInputConnection(glyph->GetOutputPort());

    //borrow the lookup table from the peds glyphs
    if(extern_glyphs_pedestrians_actor_2D->GetMapper())
        mapper->SetLookupTable(
            extern_glyphs_pedestrians_actor_2D->GetMapper()->GetLookupTable());

    //vtkActor
    pointActor = vtkActor::New();
    pointActor->SetMapper(mapper);

    /// initizliae the ID
    nextPointID=0;
}
int vtkInverseDistanceFilterCuda::RequestData(vtkInformation *vtkNotUsed(request),
					  vtkInformationVector **inputVector,
					  vtkInformationVector *outputVector)
{
	// get the info objects
	vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
	vtkInformation *outInfo = outputVector->GetInformationObject(0);
	// get the input and ouptut
	vtkPolyData *input = vtkPolyData::SafeDownCast(
		inInfo->Get(vtkDataObject::DATA_OBJECT()));
	vtkPolyData *output = vtkPolyData::SafeDownCast(
		outInfo->Get(vtkDataObject::DATA_OBJECT()));
	VTK_CREATE(outpoints, vtkPoints);
	VTK_CREATE(outScalars, vtkDoubleArray);
	vtkDoubleArray* inScalars = (vtkDoubleArray*)(input->GetPointData()->GetScalars());
	double *raw_points = (double*)malloc(sizeof(double) * 4 * input->GetNumberOfPoints()),
		*save_pos = raw_points;
	for(vtkIdType i = 0;i < input->GetNumberOfPoints();i++, save_pos += 4)
	{
		input->GetPoint(i, save_pos);
		save_pos[3] = inScalars->GetValue(i);
	}
	int h_total = input->GetNumberOfPoints();
	
	InterpolationInfo info(h_total);
	info.GetPosFromXYZArray(raw_points);
	free(raw_points);
	info.interval[0] = m_Interval[0];
	info.interval[1] = m_Interval[1];
	info.interval[2] = m_Interval[2];
	info.SetBounds(m_Bounds);
	int size = InverseDistance_SetData(&info, (float)m_PowerValue);
	float *outdata = new float[size];
	InverseDistance_ComputeData(outdata);
	double dim[3];
	int outindex = 0;
	for (dim[2] = m_Bounds.zmin;dim[2] <= m_Bounds.zmax;dim[2]+=m_Interval[2])
	{
		for (dim[1] = m_Bounds.ymin;dim[1] <= m_Bounds.ymax;dim[1]+=m_Interval[1])
		{
			for (dim[0] = m_Bounds.xmin;dim[0] <= m_Bounds.xmax;dim[0]+=m_Interval[0])
			{
				outpoints->InsertNextPoint(dim);
				outScalars->InsertNextTuple1(outdata[outindex++]);
			}
		}
	}
	delete outdata;
	printf("size: %d, outindex: %d\n", size, outindex);
	output->SetPoints(outpoints);
	output->GetPointData()->SetScalars(outScalars);
	return 1;
}
//-----------------------------------------------------------------------------
int ctkVTKRenderViewTest1(int argc, char * argv [] )
{
  QApplication app(argc, argv);

  // Command line parser
  ctkCommandLineParser parser;
  parser.addArgument("", "-I", QVariant::Bool);
  parser.addArgument("", "-D", QVariant::String);
  bool ok = false;
  QHash<QString, QVariant> parsedArgs = parser.parseArguments(app.arguments(), &ok);
  if (!ok)
    {
    std::cerr << qPrintable(parser.errorString()) << std::endl;
    return EXIT_FAILURE;
    }

  bool interactive = parsedArgs["-I"].toBool();
  QString data_directory = parsedArgs["-D"].toString();

  // Instanciate widget
  ctkVTKRenderView renderView;
  renderView.resize(300, 300);
  renderView.setBackgroundColor(QColor(Qt::red));
  renderView.setCornerAnnotationText("CTK Rocks !");
  renderView.show();

  // Instanciate VTK objects
  VTK_CREATE(vtkSphereSource, sphere);
  VTK_CREATE(vtkPolyDataMapper, sphereMapper);
  VTK_CREATE(vtkActor, sphereActor);

  // Configure actor
  sphere->SetRadius(0.25);
  sphereMapper->SetInputConnection(sphere->GetOutputPort());
  sphereActor->SetMapper(sphereMapper);

  // Add actor
  renderView.renderer()->AddActor(sphereActor);

  renderView.lookFromAxis(ctkAxesWidget::Right);
  renderView.lookFromAxis(ctkAxesWidget::Left, 10);
  renderView.lookFromAxis(ctkAxesWidget::Anterior, 1.);
  renderView.lookFromAxis(ctkAxesWidget::Posterior, 1.);
  renderView.lookFromAxis(ctkAxesWidget::Superior, 0.333333);
  renderView.lookFromAxis(ctkAxesWidget::Inferior, 0.333333);
  renderView.lookFromAxis(ctkAxesWidget::None, 100.);

  if (!interactive)
    {
    QTimer::singleShot(1000, &app, SLOT(quit()));
    }
  return app.exec();
}
示例#5
0
TrailPlotter::TrailPlotter()
{
    // trails sources
    VTK_CREATE (vtkDiskSource, agentShape);
    agentShape->SetCircumferentialResolution(20);
    agentShape->SetInnerRadius(0);
    agentShape->SetOuterRadius(30);

    //speed the rendering using triangles stripers
    vtkTriangleFilter *tris = vtkTriangleFilter::New();
    tris->SetInputConnection(agentShape->GetOutputPort());
    //tris->GetOutput()->ReleaseData();

    vtkStripper *strip = vtkStripper::New();
    strip->SetInputConnection(tris->GetOutputPort());
    //strip->GetOutput()->ReleaseData();


    _appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
    _appendFilter->SetInputConnection(strip->GetOutputPort());

    // Remove any duplicate points.
    _cleanFilter = vtkSmartPointer<vtkCleanPolyData>::New();
    //_cleanFilter->SetInputConnection(_appendFilter->GetOutputPort());

    //Create a mapper and actor
    vtkSmartPointer<vtkPolyDataMapper> mapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
    //mapper->SetInputConnection(_cleanFilter->GetOutputPort());

    _trailActor =  vtkSmartPointer<vtkActor>::New();
    //_trailActor->SetMapper(mapper);
}
示例#6
0
void
pcl::visualization::PCLPlotter::addPlotData (
    double const* array_X, double const* array_Y, 
    unsigned long size, char const * name /* = "Y Axis" */, 
    int type, char const* color)
{
  //updating the current plot ID
  current_plot_++;
  
  //creating a permanent copy of the arrays
  double *permanent_X = new double[size];
  double *permanent_Y = new double[size];
  memcpy(permanent_X, array_X, size*sizeof(double));
  memcpy(permanent_Y, array_Y, size*sizeof(double));
  
  //transforming data to be fed to the vtkChartXY
  VTK_CREATE (vtkTable, table);

  VTK_CREATE (vtkDoubleArray, varray_X);
  varray_X->SetName ("X Axis");
  varray_X->SetArray (permanent_X, size, 1);
  table->AddColumn (varray_X);

  VTK_CREATE (vtkDoubleArray, varray_Y);
  varray_Y->SetName (name);
  varray_Y->SetArray (permanent_Y, size, 1);
  table->AddColumn (varray_Y);

  //adding to chart
  //vtkPlot *line = chart_->AddPlot(vtkChart::LINE);
  vtkPlot *line = this->AddPlot (type);
  line->SetInput (table, 0, 1);
  line->SetWidth (1);

  if (color == NULL)    //color automatically based on the ColorScheme
  {
    vtkColor3ub vcolor = color_series_->GetColorRepeating (current_plot_);
    line->SetColor (vcolor[0], vcolor[1], vcolor[2], 255);
  }
  else                  //add the specific color
    line->SetColor (color[0], color[1], color[2], color[3]);
}
示例#7
0
文件: p2.cpp 项目: igorpejic/graphics
int main()
{
    // Create a mapper and actor
    VTK_CREATE(vtkDataSetMapper, mapper);
    vtkSmartPointer<vtkStructuredGrid> g = createGrid(6,10);
#if VTK_MAJOR_VERSION <= 5
    mapper->SetInputConnection(g->GetProducerPort());
#else
    mapper->SetInputData(g);
#endif

    VTK_CREATE(vtkActor, g_actor);
    g_actor->SetMapper(mapper);
    g_actor->GetProperty()->SetRepresentationToWireframe();

    VTK_CREATE(vtkRenderer, ren);
    ren->AddActor(g_actor);

    ren->SetBackground(.1,.2,.3);

    VTK_CREATE(vtkRenderWindow, renw);
    renw->AddRenderer(ren);

    VTK_CREATE(vtkInteractorStyleTrackballCamera, style);

    VTK_CREATE(vtkRenderWindowInteractor, iren);
    iren->SetRenderWindow(renw);
    iren->SetInteractorStyle(style);
    iren->Initialize();
    iren->Start();
    return 0;
}
//---------------------------------------------------------------------------
void RenderWindowItem::SetupImageMapperActor(double colorWindow, double colorLevel)
{
  assert(this->Renderer);
  assert(!this->ImageMapper);

  // Instantiate an image mapper
  this->ImageMapper = vtkSmartPointer<vtkImageMapper>::New();
  this->ImageMapper->SetColorWindow(colorWindow);
  this->ImageMapper->SetColorLevel(colorLevel);

  // .. and its corresponding 2D actor
  VTK_CREATE(vtkActor2D, actor2D);
  actor2D->SetMapper(this->ImageMapper);
  actor2D->GetProperty()->SetDisplayLocationToBackground();

  // .. and add it to the renderer
  this->Renderer->AddActor2D(actor2D);
}
示例#9
0
// Constructor
SimpleView::SimpleView() 
{
  this->ui = new Ui_SimpleView;
  this->ui->setupUi(this);

  // Qt Table View
  this->TableView = vtkSmartPointer<vtkQtTableView>::New();

  // Place the table view in the designer form
  this->ui->tableFrame->layout()->addWidget(this->TableView->GetWidget());

  // Geometry
  VTK_CREATE(vtkVectorText, text);
  text->SetText("VTK and Qt!");
  VTK_CREATE(vtkElevationFilter, elevation);
  elevation->SetInputConnection(text->GetOutputPort());
  elevation->SetLowPoint(0,0,0);
  elevation->SetHighPoint(10,0,0);

  // Mapper
  VTK_CREATE(vtkPolyDataMapper, mapper);
  mapper->ImmediateModeRenderingOn();
  mapper->SetInputConnection(elevation->GetOutputPort());

  // Actor in scene
  VTK_CREATE(vtkActor, actor);
  actor->SetMapper(mapper);

  // VTK Renderer
  VTK_CREATE(vtkRenderer, ren);

  // Add Actor to renderer
  ren->AddActor(actor);

  // VTK/Qt wedded
  this->ui->qvtkWidget->GetRenderWindow()->AddRenderer(ren);

  // Just a bit of Qt interest: Culling off the
  // point data and handing it to a vtkQtTableView
  VTK_CREATE(vtkDataObjectToTable, toTable);
  toTable->SetInputConnection(elevation->GetOutputPort());
  toTable->SetFieldType(vtkDataObjectToTable::POINT_DATA);

  // Here we take the end of the VTK pipeline and give it to a Qt View
  this->TableView->SetRepresentationFromInputConnection(toTable->GetOutputPort());

  // Set up action signals and slots
  connect(this->ui->actionOpenFile, SIGNAL(triggered()), this, SLOT(slotOpenFile()));
  connect(this->ui->actionExit, SIGNAL(triggered()), this, SLOT(slotExit()));

};
示例#10
0
int vtkInverseDistanceFilter::RequestData(vtkInformation *vtkNotUsed(request),
			       vtkInformationVector **inputVector,
			       vtkInformationVector *outputVector)
{
	// get the info objects
	vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
	vtkInformation *outInfo = outputVector->GetInformationObject(0);

	// get the input and ouptut
	vtkPolyData *input = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
	vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));

	VTK_CREATE(outpoints, vtkPoints);
	VTK_CREATE(outScalars, vtkDoubleArray);
	vtkDoubleArray* inScalars = (vtkDoubleArray*)(input->GetPointData()->GetScalars());
	const int MAX_POINTS = input->GetNumberOfPoints();
	double *raw_points = (double*)malloc(sizeof(double) * 4 * input->GetNumberOfPoints()),
		*save_pos = raw_points;
	
	for(vtkIdType i = 0; i < input->GetNumberOfPoints(); i++, save_pos += 4)
	{
		input->GetPoint(i, save_pos);
		save_pos[3] = inScalars->GetValue(i);
	}
	doubles vals;
	double dim[3];
	{ // fix Numerical error
		m_Bounds.xmax += m_Interval[0]*0.5;
		m_Bounds.ymax += m_Interval[1]*0.5;
		m_Bounds.zmax += m_Interval[2]*0.5;
	}
	for (dim[2] = m_Bounds.zmin;dim[2] <= m_Bounds.zmax;dim[2]+=m_Interval[2])
	{
		for (dim[1] = m_Bounds.ymin;dim[1] <= m_Bounds.ymax;dim[1]+=m_Interval[1])
		{
			for (dim[0] = m_Bounds.xmin;dim[0] <= m_Bounds.xmax;dim[0]+=m_Interval[0])
			{
				outpoints->InsertNextPoint(dim);
				double sum = 0, sum2 = 0, dis;
				for (int i = 0;i < MAX_POINTS;i++)
				{
					dis = sqrt(vtkMath::Distance2BetweenPoints(raw_points+i*4, dim));
					if (dis<0.001)
					{
						outScalars->InsertNextTuple1(*(raw_points+i*4+3));
						break;
					}
					double tmp = pow(dis, -m_PowerValue);
					sum += tmp;
					sum2 += tmp*(*(raw_points+i*4+3)); // *(raw_points+i*4+3) is as same as inScalars->GetValue(i);
				}
				if (dis>=0.001)
				{
					sum2 /= sum;
					outScalars->InsertNextTuple1(sum2);
				}
			}
		}
	}
	{ // fix Numerical error
		m_Bounds.xmax -= m_Interval[0]*0.5;
		m_Bounds.ymax -= m_Interval[1]*0.5;
		m_Bounds.zmax -= m_Interval[2]*0.5;
	}
	output->SetPoints(outpoints);
	output->GetPointData()->SetScalars(outScalars);
	free(raw_points);
	return 1;
}
int main(int argc, char* argv[])
{
    typedef double DecisionVariable_t;
    typedef std::mt19937 RNG_t;
    unsigned int seed = 1;
    double eta = 10;
    double crossover_probability = 1.0;
    double eps = 0.00001;
    double proportion_crossed = 1.0;
    RNG_t rng(seed);
    
    DebsSBXCrossover<RNG_t> crossover_tester(rng, eta, crossover_probability, eps, proportion_crossed);
    
    int number_dvs = 1; //number of decision variables
    double min_value = -1.0;
    double max_value = 8.0;
    std::vector<double> lower_bounds(number_dvs, min_value);
    std::vector<double> upper_bounds(number_dvs, max_value);
    std::vector<int> lower_bounds_i;
    std::vector<int> upper_bounds_i;
    std::vector<MinOrMaxType> min_or_max(1, MINIMISATION);
    
//    std::vector<DecisionVariable_t> parent1_dv_values {2};
//    std::vector<DecisionVariable_t> parent2_dv_values {5};
    ProblemDefinitions defs(lower_bounds, upper_bounds,lower_bounds_i, upper_bounds_i, min_or_max, 0);
    Individual parent1(defs);
    Individual parent2(defs);
    
    std::vector<double> results;
    
    int num_samples = 1000000;
    for (int i = 0; i < num_samples; ++i)
    {
        Individual child1(parent1);
        Individual child2(parent2);
        crossover_tester.crossover_implementation(child1, child2);
        results.push_back(child1.getRealDV(0));
        results.push_back(child2.getRealDV(0));
//        std::cout << child1[0] << std::endl;
//        std::cout << child2[0] << std::endl;
    }
    
#ifdef WITH_VTK
    // plot results.
    // Set up a 2D scene, add an XY chart to it
    VTK_CREATE(vtkContextView, view);
    view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
    view->GetRenderWindow()->SetSize(400, 300);
    VTK_CREATE(vtkChartXY, chart);
    view->GetScene()->AddItem(chart);
    
    // Create a table with some points in it...
    VTK_CREATE(vtkTable, table);
    
    VTK_CREATE(vtkIntArray, arrBin);
    arrBin->SetName("decision variable value");
    table->AddColumn(arrBin);
    
    VTK_CREATE(vtkIntArray, arrFrequency);
    arrFrequency->SetName("Frequency");
    table->AddColumn(arrFrequency);
    
    int num_bins = 50;
    table->SetNumberOfRows(num_bins);
    
    std::vector<int> frequency_count(num_bins);
//    std::vector<std::string> bin_names(num_bins);
    std::vector<int> bin_names(num_bins);
    
    for (int i = 0; i < num_samples; ++i)
    {
        frequency_count[int((results[i] - min_value) / (max_value - min_value) * num_bins)]++;
    }
    
    for (int i = 0; i < num_bins; ++i)
    {
//        bin_names[i] = std::to_string((double(i) / double(num_bins)) * (max_value-min_value) + min_value);
        bin_names[i] = i;
    }
    
    for (int i = 0; i < num_bins; i++)
    {
        table->SetValue(i,0,bin_names[i]);
        table->SetValue(i,1,frequency_count[i]);
    }
    
    // Add multiple line plots, setting the colors etc
    vtkPlot *line = 0;
    
    line = chart->AddPlot(vtkChart::BAR);
#if VTK_MAJOR_VERSION <= 5
    line->SetInput(table, 0, 1);
#else
    line->SetInputData(table, 0, 1);
#endif
    line->SetColor(0, 255, 0, 255);
    
    //Finally render the scene and compare the image to a reference image
    view->GetRenderWindow()->SetMultiSamples(0);
    view->GetInteractor()->Initialize();
    view->GetInteractor()->Start();
#endif
    
}
示例#12
0
//---------------------------------------------------------------------------
void RenderWindowItem::SetupHighlightedBoxActor(const double highlightedBoxColor[3], bool visible)
{
  assert(this->Renderer);
  assert(!this->HighlightedBoxActor);
  
  // Create a highlight actor (2D box around viewport)
  VTK_CREATE(vtkPolyData, poly);
  VTK_CREATE(vtkPoints, points);
  // Normalized Viewport means :
  // 0. -> 0;
  // 1. -> width - 1 ;
  // For a line of a width of 1, from (0.f,0.f) to (10.f,0.f), the line is on
  // 2 pixels. What pixel to draw the line on ?
  //
  //     |       |       |       |       |       |       |
  //  1  |       |       |       |       |       |       |
  //     |       |       |       |       |       |       |
  //     +-------+-------+-------+-------+-------+-------+
  //     |       |       |       |       |       |       |
  //  0  | What pixel    |================================
  //     | line shall    |
  //     +--be drawn---(0,0)
  //     |  above or     |
  // -1  |   below?      |================================
  //     |       |       |       |       |       |       |
  //  ^  +-------+-------+-------+-------+-------+-------+
  //     |       |       |       |       |       |       |
  // 1px |       |       |       |       |       |       |
  //     |       |       |       |       |       |       |
  //  V  +-------+-------+-------+-------+-------+-------+
  //     <  1px  >  -1       0       1       2       3
  // It depends of the graphic card, this is why we need to add an offset.
  // 0.0002 seems to work for most of the window sizes.
  double shift = 0.0002;
  points->InsertNextPoint(0. + shift, 0. + shift, 0); // bottom-left
  points->InsertNextPoint(1. + shift, 0. + shift, 0); // bottom-right
  points->InsertNextPoint(1. + shift, 1. + shift + 0.1, 0); // top-right to fill the 1,1 pixel
  points->InsertNextPoint(1. + shift, 1. + shift, 0); // top-right
  points->InsertNextPoint(0. + shift, 1. + shift, 0); // top-left
  points->InsertNextPoint(0. + shift, 0. + shift - 0.1, 0); // bottom-left to fill the 0,0 pixel.
  
  VTK_CREATE(vtkCellArray, cells);
  cells->InsertNextCell(6);
  cells->InsertCellPoint(0);
  cells->InsertCellPoint(1);
  cells->InsertCellPoint(2);
  cells->InsertCellPoint(3);
  cells->InsertCellPoint(4);
  cells->InsertCellPoint(5);
  poly->SetPoints(points);
  poly->SetLines(cells);

  VTK_CREATE(vtkCoordinate, coordinate);
  coordinate->SetCoordinateSystemToNormalizedViewport();
  coordinate->SetViewport(this->Renderer);

  VTK_CREATE(vtkPolyDataMapper2D, polyDataMapper);
  polyDataMapper->SetInput(poly);
  polyDataMapper->SetTransformCoordinate(coordinate);
  polyDataMapper->SetTransformCoordinateUseDouble(true);

  this->HighlightedBoxActor = vtkSmartPointer<vtkActor2D>::New();
  this->HighlightedBoxActor->SetMapper(polyDataMapper);
  this->HighlightedBoxActor->GetProperty()->SetColor(highlightedBoxColor[0],
                                                     highlightedBoxColor[1],
                                                     highlightedBoxColor[2]);
  this->HighlightedBoxActor->GetProperty()->SetDisplayLocationToForeground();
  this->HighlightedBoxActor->GetProperty()->SetLineWidth(1.0f);
  this->HighlightedBoxActor->SetVisibility(visible);

  this->Renderer->AddActor2D(this->HighlightedBoxActor);
}
int vtkLimitedInverseDistanceFilter::RequestData( vtkInformation *vtkNotUsed(request),
						 vtkInformationVector	**inputVector,
						 vtkInformationVector	*outputVector )
{
	// get the info objects
	vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
	vtkInformation *outInfo = outputVector->GetInformationObject(0);

	// get the input and ouptut
	vtkPolyData *input = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
	vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
	
	// new id list to get points
	VTK_CREATE(ids, vtkIdList);
	VTK_CREATE(kDTree, vtkKdTreePointLocator);
	VTK_CREATE(outpoints, vtkPoints);
	VTK_CREATE(outScalars, vtkDoubleArray);
	vtkDoubleArray* inScalars = (vtkDoubleArray*)(input->GetPointData()->GetScalars());
	double *raw_points = (double*)malloc(sizeof(double) * 4 * input->GetNumberOfPoints()),
		*save_pos = raw_points;

	// set kDtree and build
	kDTree->SetDataSet(input);
	kDTree->BuildLocator();

	// set safe number of points
	if (m_LimitNum > input->GetNumberOfPoints())
		m_LimitNum = input->GetNumberOfPoints();

	for (vtkIdType i = 0; i < input->GetNumberOfPoints(); i++, save_pos += 4)
	{
		input->GetPoint(i, save_pos);
		save_pos[3] = inScalars->GetValue(i);
	}
	save_pos = raw_points;
	doubles vals;
	double	dim[3];
	{ // fix Numerical error
		m_Bounds.xmax += m_Interval[0]*0.5;
		m_Bounds.ymax += m_Interval[1]*0.5;
		m_Bounds.zmax += m_Interval[2]*0.5;
	}
	float sqr2 = m_Radius*m_Radius;
	struct myvalue
	{
		myvalue(){}
		myvalue(double d, int i)
			:distance(d), index(i)
		{
		}
		double distance;
		int index;
		bool operator < (const myvalue& rhs)
		{
			return distance < rhs.distance;
		}
	};
	std::vector<myvalue> myvalues;
	for (dim[2] = m_Bounds.zmin; dim[2] <= m_Bounds.zmax; dim[2] += m_Interval[2])
	{
		for (dim[1] = m_Bounds.ymin; dim[1] <= m_Bounds.ymax; dim[1] += m_Interval[1])
		{
			for (dim[0] = m_Bounds.xmin; dim[0] <= m_Bounds.xmax; dim[0] += m_Interval[0])
			{
				outpoints->InsertNextPoint(dim);
				doubles weights;
				int	zero_pos_index = -1;
				save_pos = raw_points;
				if (LIMIT_NUMBER == m_limitMethod)
				{
					kDTree->FindClosestNPoints(m_LimitNum, dim, ids);
					const int MAX_POINTS = ids->GetNumberOfIds();
					double sum = 0, sum2 = 0, dis;
					if (ids->GetNumberOfIds() > 0)
					{
						myvalues.clear();
						int max_ids = ids->GetNumberOfIds();
						for (int i = 0; i < max_ids; i++)
						{
							const int index = ids->GetId(i);
							dis = vtkMath::Distance2BetweenPoints(raw_points+index*4, dim);
							dis = sqrt(dis);
							myvalue mv;
							mv.distance = dis;
							mv.index = index;
							myvalues.push_back(mv);
							if (dis<0.001)
							{
								outScalars->InsertNextTuple1(*(raw_points+index*4+3));
								break;
							}
						}
						std::nth_element(myvalues.begin(), myvalues.begin()+m_LimitNum, myvalues.end());
						for (int i = 0;i < m_LimitNum;i++)
						{
							double tmp = pow(myvalues[i].distance, -m_PowerValue);
							sum += tmp;
							sum2 += tmp*(*(raw_points+myvalues[i].index*4+3)); // *(raw_points+i*4+3) is as same as inScalars->GetValue(i);
						}
						if (dis>=0.001)
						{
							sum2 /= sum;
							outScalars->InsertNextTuple1(sum2);
						}
					}
					else
					{
						outScalars->InsertNextTuple1(m_NullValue);
					}
				}
				else if (LIMIT_RADIUS == m_limitMethod)
				{
					kDTree->FindPointsWithinRadius(m_Radius, dim, ids);
					const int MAX_POINTS = ids->GetNumberOfIds();
					double sum = 0, sum2 = 0, dis;
					if (ids->GetNumberOfIds() > 0)
					{
						int max_ids = ids->GetNumberOfIds();
						//if (LIMIT_NUMBER == m_limitMethod) max_ids = m_LimitNum;
						for (int i = 0; i < max_ids; i++)
						{
							const int index = ids->GetId(i);
							dis = vtkMath::Distance2BetweenPoints(raw_points+index*4, dim);
							dis = sqrt(dis);
							if (dis<0.001)
							{
								outScalars->InsertNextTuple1(*(raw_points+index*4+3));
								break;
							}
							double tmp = pow(dis, -m_PowerValue);
							sum += tmp;
							sum2 += tmp*(*(raw_points+index*4+3)); // *(raw_points+i*4+3) is as same as inScalars->GetValue(i);
						}
						if (dis>=0.001)
						{
							sum2 /= sum;
							outScalars->InsertNextTuple1(sum2);
						}
					}
					else
					{
						outScalars->InsertNextTuple1(m_NullValue);
					}
				}
			}
		}
	}
	{ // fix Numerical error
		m_Bounds.xmax -= m_Interval[0]*0.5;
		m_Bounds.ymax -= m_Interval[1]*0.5;
		m_Bounds.zmax -= m_Interval[2]*0.5;
	}
	// set out points
	output->SetPoints(outpoints);
	output->GetPointData()->SetScalars(outScalars);
	free(raw_points);
	return 1;
}