36 #include "QGoGUILibConfigure.h"
39 #include "vtkPolyData.h"
40 #include "vtkPointData.h"
43 #include "vtkClipPolyData.h"
45 #include "vtkCutter.h"
48 #include "vtkSphereSource.h"
50 #include "vtkCubeSource.h"
51 #include "vtkTriangleFilter.h"
53 #include "vtkCylinderSource.h"
72 name =
"2D Shapes in 1 mesh";
100 std::cerr <<
"Radius should be > 0 " << std::endl;
104 double *center2 =
new double[3];
110 for (
int i = 0; i <
getPoints()->GetNumberOfPoints(); i++ )
118 vtkPolyData *testing = NULL;
138 vtkPlane *implicitFunction = vtkPlane::New();
139 implicitFunction->SetNormal(0, 0, 1);
140 implicitFunction->SetOrigin(center2[0], center2[1], center2[2]);
142 vtkCutter *cutter = vtkCutter::New();
143 cutter->SetInput(testing);
144 cutter->SetCutFunction(implicitFunction);
150 implicitFunction->Delete();
164 vtkPlane *implicitFunction = vtkPlane::New();
165 implicitFunction->SetNormal(0, 0, 1);
167 vtkCutter *cutter = vtkCutter::New();
168 cutter->SetInput(testing);
169 cutter->SetCutFunction(implicitFunction);
177 ( center2[0] -
getRadius() + static_cast< double >( j + 1 ) * step ),
178 ( center2[1] -
getRadius() + static_cast< double >( j + 1 ) * step ),
179 ( center2[2] -
getRadius() + static_cast< double >( j + 1 ) * step ) );
185 implicitFunction->Delete();
226 vtkSmartPointer< vtkImageData > iImage)
229 vtkSphereSource *sphere = vtkSphereSource::New();
231 sphere->SetRadius( iRadius );
232 sphere->SetCenter(iCenter);
234 sphere->GetOutput()->GetPointData()->SetNormals(NULL);
237 vtkBox *implicitFunction = vtkBox::New();
239 implicitFunction->SetBounds( iImage->GetBounds() );
241 vtkClipPolyData *cutter = vtkClipPolyData::New();
242 cutter->SetInput( sphere->GetOutput() );
243 cutter->InsideOutOn();
244 cutter->SetClipFunction(implicitFunction);
247 vtkPolyData *output = vtkPolyData::New();
248 output->DeepCopy( cutter->GetOutput() );
250 implicitFunction->Delete();
262 vtkSmartPointer< vtkImageData > iImage)
304 vtkCubeSource *cube = vtkCubeSource::New();
306 cube->SetCenter(iCenter);
307 cube->SetXLength( 2 * iRadius);
308 cube->SetYLength( 2 * iRadius);
309 cube->SetZLength( 2 * iRadius);
311 cube->GetOutput()->GetPointData()->SetNormals(NULL);
313 vtkTriangleFilter *triangle = vtkTriangleFilter::New();
314 triangle->SetInput( cube->GetOutput() );
318 vtkBox *implicitFunction = vtkBox::New();
319 implicitFunction->SetBounds( iImage->GetBounds() );
321 vtkClipPolyData *cutter = vtkClipPolyData::New();
322 cutter->SetInput( triangle->GetOutput() );
323 cutter->InsideOutOn();
324 cutter->SetClipFunction(implicitFunction);
327 vtkPolyData *output = vtkPolyData::New();
328 output->DeepCopy( cutter->GetOutput() );
330 implicitFunction->Delete();
345 vtkCylinderSource *cylinder = vtkCylinderSource::New();
349 cylinder->SetCenter(iCenter);
350 cylinder->SetResolution(10);
352 cylinder->GetOutput()->GetPointData()->SetNormals(NULL);
354 vtkTriangleFilter *triangle = vtkTriangleFilter::New();
355 triangle->SetInput( cylinder->GetOutput() );
357 vtkPolyData *output = vtkPolyData::New();
358 output->DeepCopy( triangle->GetOutput() );
369 double iRadius, std::vector< vtkPoints* >* iPoints, std::string iShape,
373 std::vector<vtkPolyData*> oMeshes = std::vector<vtkPolyData*>();
376 std::cerr <<
"Radius should be > 0 " << std::endl;
380 vtkImageData* temp_image = iImages->
getImageBW(iChannel);
384 for (
size_t id = 0;
id < iPoints->size();
id++ )
387 for ( vtkIdType i = 0; i < (*iPoints)[id]->GetNumberOfPoints(); i++ )
389 (*iPoints)[id]->GetPoint(i, center2);
394 vtkPolyData * MeshPolydata = NULL;
396 if (iShape ==
"Sphere")
402 if (iShape ==
"Cube")
404 MeshPolydata =
GenerateCube( center2, iRadius, temp_image );
408 std::cout<<
"doesn't know the chosen shape ";
409 std::cout <<
"Debug: In " << __FILE__ <<
", line " << __LINE__;
410 std::cout << std::endl;
413 oMeshes.push_back(MeshPolydata);
423 std::string iShape,
int iSampling,
424 std::vector< vtkPoints* >* iPoints,
427 std::vector<std::vector<vtkPolyData*> > oSetOfContours =
428 std::vector<std::vector<vtkPolyData*> >();
431 return oSetOfContours;