VMTK
Loading...
Searching...
No Matches
vtkvmtkSurfMeshWrapper.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkSurfMeshWrapper.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:47:48 $
7Version: $Revision: 1.4 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23#include "vtkPolyData.h"
24#include "vtkPoints.h"
25#include "vtkCellArray.h"
26#include "vtkObjectFactory.h"
27#include "vtkInformation.h"
28#include "vtkInformationVector.h"
29#include "SurfaceMesher.h"
30
31
33
38
42
43class Remesh : public SurfaceMesher::RemeshSurface {
44public:
45
47 { this->NodeSpacing = 0.1; }
48 Remesh(real nodeSpacing)
49 { this->NodeSpacing = nodeSpacing; }
50
51 real NodeSpace(real *x)
52 {
53 return this->NodeSpacing;
54 }
55
56private:
57
58 real NodeSpacing;
59};
60
62 vtkInformation *vtkNotUsed(request),
63 vtkInformationVector **inputVector,
64 vtkInformationVector *outputVector)
65{
66 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
67 vtkInformation *outInfo = outputVector->GetInformationObject(0);
68
69 vtkPolyData *input = vtkPolyData::SafeDownCast(
70 inInfo->Get(vtkDataObject::DATA_OBJECT()));
71 vtkPolyData *output = vtkPolyData::SafeDownCast(
72 outInfo->Get(vtkDataObject::DATA_OBJECT()));
73
74 Remesh *nb = new Remesh(this->NodeSpacing);
75
76 int numberOfInputPoints = input->GetNumberOfPoints();
77 nb->SetNumberOfPoints(numberOfInputPoints);
78
79 double point[3];
80 real xpos[3];
81 int i;
82 for (i=0; i<numberOfInputPoints; i++)
83 {
84 input->GetPoint(i,point);
85 xpos[0] = static_cast<real>(point[0]);
86 xpos[1] = static_cast<real>(point[1]);
87 xpos[2] = static_cast<real>(point[2]);
88 nb->AddPoint(i,xpos[0],xpos[1],xpos[2]);
89 }
90
91 input->BuildCells();
92 int numberOfInputCells = input->GetNumberOfCells();
93 vtkIdType npts, *pts;
94 for (i=0; i<numberOfInputCells; i++)
95 {
96 if (input->GetCellType(i) != VTK_TRIANGLE)
97 {
98 continue;
99 }
100 input->GetCellPoints(i,npts,pts);
101 nb->AddTriangle(pts[0],pts[1],pts[2]);
102 }
103
104 try
105 {
106 nb->Run2D();
107 }
108 catch(Error *e)
109 {
110 e->Print(std::cerr);
111 }
112
113 nb->IterateOnOutput(false);
114
115 vtkPoints* outputPoints = vtkPoints::New();
116 vtkCellArray* outputCellArray = vtkCellArray::New();
117
118 while (nb->NextNode(xpos)!=-1)
119 {
120 point[0] = static_cast<double>(xpos[0]);
121 point[1] = static_cast<double>(xpos[1]);
122 point[2] = static_cast<double>(xpos[2]);
123 outputPoints->InsertNextPoint(point);
124 }
125
126 int icorn[3];
127 while (nb->NextCell(icorn))
128 {
129 outputCellArray->InsertNextCell(3,icorn);
130 }
131
132 output->SetPoints(outputPoints);
133 output->SetPolys(outputCellArray);
134
135 outputPoints->Delete();
136 outputCellArray->Delete();
137
138 delete nb;
139
140 return 1;
141}
142
143void vtkvmtkSurfMeshWrapper::PrintSelf(std::ostream& os, vtkIndent indent)
144{
145 this->Superclass::PrintSelf(os,indent);
146}
Remesh(real nodeSpacing)
real NodeSpace(real *x)
Wraps the surfmesh surface mesh generator by Gordan Stuhne; may not be working.
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkStandardNewMacro(vtkvmtkSurfMeshWrapper)