VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataSizingFunction.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkPolyDataSizingFunction.cxx,v $
5Language: C++
6Date: $Date: 2006/07/17 09:53:14 $
7Version: $Revision: 1.6 $
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 "vtkPointData.h"
25#include "vtkDoubleArray.h"
26#include "vtkTriangle.h"
27#include "vtkIdList.h"
28#include "vtkInformation.h"
29#include "vtkInformationVector.h"
30#include "vtkObjectFactory.h"
31
32
34
40
49
51 vtkInformation *vtkNotUsed(request),
52 vtkInformationVector **inputVector,
53 vtkInformationVector *outputVector)
54{
55 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
56 vtkInformation *outInfo = outputVector->GetInformationObject(0);
57
58 vtkPolyData *input = vtkPolyData::SafeDownCast(
59 inInfo->Get(vtkDataObject::DATA_OBJECT()));
60 vtkPolyData *output = vtkPolyData::SafeDownCast(
61 outInfo->Get(vtkDataObject::DATA_OBJECT()));
62
63 if (input->GetNumberOfPoints() < 1)
64 {
65 return 1;
66 }
67
68 if (!this->SizingFunctionArrayName)
69 {
70 vtkErrorMacro(<<"No SizingFunctionArrayName specified");
71 return 1;
72 }
73
74 input->BuildCells();
75 input->BuildLinks();
76
77 int numberOfPoints = input->GetNumberOfPoints();
78
79 vtkDoubleArray* sizingFunctionArray = vtkDoubleArray::New();
80 sizingFunctionArray->SetName(this->SizingFunctionArrayName);
81 sizingFunctionArray->SetNumberOfTuples(numberOfPoints);
82 sizingFunctionArray->FillComponent(0,0.0);
83
84 vtkIdList* pointCells = vtkIdList::New();
85
86 int i, j;
87 for (i=0; i<numberOfPoints; i++)
88 {
89 input->GetPointCells(i,pointCells);
90 int numberOfPointCells = pointCells->GetNumberOfIds();
91 double averageArea = 0.0;
92 if (numberOfPointCells == 0)
93 {
94 continue;
95 }
96 for (j=0; j<numberOfPointCells; j++)
97 {
98 vtkTriangle* triangle = vtkTriangle::SafeDownCast(input->GetCell(pointCells->GetId(j)));
99 if (!triangle)
100 {
101 vtkErrorMacro(<<"Cell not triangle: skipping cell for sizing function computation");
102 }
103 double point0[3], point1[3], point2[3];
104 triangle->GetPoints()->GetPoint(0,point0);
105 triangle->GetPoints()->GetPoint(1,point1);
106 triangle->GetPoints()->GetPoint(2,point2);
107 averageArea += vtkTriangle::TriangleArea(point0,point1,point2);
108 }
109 averageArea /= numberOfPointCells;
110
111 double sizingFunction = sqrt(averageArea) * this->ScaleFactor;
112 sizingFunctionArray->SetValue(i,sizingFunction);
113 }
114
115 output->DeepCopy(input);
116 output->GetPointData()->AddArray(sizingFunctionArray);
117
118 sizingFunctionArray->Delete();
119 pointCells->Delete();
120
121 return 1;
122}
123
124void vtkvmtkPolyDataSizingFunction::PrintSelf(std::ostream& os, vtkIndent indent)
125{
126 this->Superclass::PrintSelf(os,indent);
127}
Construct a mesh-size field, sampled on the input surface points, from the local surface triangle siz...
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkStandardNewMacro(vtkvmtkPolyDataSizingFunction)