1 #include "vvClipPolyData.h"
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"
14 vtkStandardNewMacro(vvClipPolyData);
16 vvClipPolyData::vvClipPolyData()
18 this->SetNumberOfInputPorts(1);
19 this->SetNumberOfOutputPorts(1);
22 vvClipPolyData::~vvClipPolyData()
27 int vvClipPolyData::RequestData(vtkInformation *vtkNotUsed(request),
28 vtkInformationVector **inputVector,
29 vtkInformationVector *outputVector)
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()));
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++) {
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);
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);
65 //vtkErrorMacro("vvClipPolyData - NOT IMPLEMENTED");
69 output->ShallowCopy(input);
70 output->SetPoints(outputPoints);
71 output->GetPointData()->AddArray(outputStrings);
75 //----------------------------------------------------------------------------
77 void vvClipPolyData::PrintSelf(ostream& os, vtkIndent indent)
79 this->Superclass::PrintSelf(os,indent);