]> Creatis software - clitk.git/blob - vv/vvClipPolyData.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvClipPolyData.cxx
1 #include "vvClipPolyData.h"
2
3 #include "vtkObjectFactory.h"
4 #include "vtkStreamingDemandDrivenPipeline.h"
5 #include "vtkInformationVector.h"
6 #include "vtkInformation.h"
7 #include "vtkDataObject.h"
8 #include "vtkSmartPointer.h"
9 #include "vtkImplicitFunction.h"
10 #include "vtkStringArray.h"
11 #include "vtkPointData.h"
12
13
14 vtkStandardNewMacro(vvClipPolyData);
15
16 vvClipPolyData::vvClipPolyData()
17 {
18   this->SetNumberOfInputPorts(1);
19   this->SetNumberOfOutputPorts(1);
20 }
21
22 vvClipPolyData::~vvClipPolyData()
23 {
24
25 }
26
27 int vvClipPolyData::RequestData(vtkInformation *vtkNotUsed(request),
28                                              vtkInformationVector **inputVector,
29                                              vtkInformationVector *outputVector)
30 {
31     // get the info objects
32     vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
33     vtkInformation *outInfo = outputVector->GetInformationObject(0);
34     // get the input and ouptut
35     vtkPolyData *input = vtkPolyData::SafeDownCast(
36                              inInfo->Get(vtkDataObject::DATA_OBJECT()));
37     vtkStringArray* inputLabels = vtkStringArray::SafeDownCast(input->GetPointData()->GetAbstractArray("labels"));
38     vtkPolyData *output = vtkPolyData::SafeDownCast(
39                             outInfo->Get(vtkDataObject::DATA_OBJECT()));
40     //
41     vtkImplicitFunction* currentImpliciteFunction = this->GetClipFunction();
42     int insideOutValue = this->GetInsideOut();
43     //if insideOutValue=0; we want to retrieve ouside points
44     //if insideOutValue=1; we want to retrieve inside points
45     vtkSmartPointer<vtkPoints> outputPoints = vtkSmartPointer<vtkPoints>::New();
46     vtkSmartPointer<vtkStringArray> outputStrings = vtkSmartPointer<vtkStringArray>::New();
47     outputStrings->SetName("labels");
48     for(vtkIdType i=0;i<input->GetNumberOfPoints();i++) {
49         //
50         double* currentPoint = input->GetPoint(i);
51         double currentIFvalue = currentImpliciteFunction->FunctionValue(currentPoint);
52         //if currentIFvalue>0, current point is outside the clip
53         if (currentIFvalue>0 && insideOutValue==0) {
54             outputPoints->InsertNextPoint(currentPoint);
55             vtkStdString label = inputLabels->GetValue(i);
56             outputStrings->InsertNextValue(label);
57         }
58         //currentIFvalue<=0, current point is inside the clip
59         else if (currentIFvalue<=0 && insideOutValue==1) {
60             outputPoints->InsertNextPoint(currentPoint);
61             vtkStdString label = inputLabels->GetValue(i);
62             outputStrings->InsertNextValue(label);
63         }
64         else {
65             //vtkErrorMacro("vvClipPolyData - NOT IMPLEMENTED");
66         }
67     }
68     //
69     output->ShallowCopy(input);
70     output->SetPoints(outputPoints);
71     output->GetPointData()->AddArray(outputStrings);
72     return 1;
73 }
74
75 //----------------------------------------------------------------------------
76
77 void vvClipPolyData::PrintSelf(ostream& os, vtkIndent indent)
78 {
79     this->Superclass::PrintSelf(os,indent);
80 }