File: itkFastMarchingQuadEdgeMeshFilterBaseTest2.cxx

package info (click to toggle)
insighttoolkit5 5.4.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 704,384 kB
  • sloc: cpp: 783,592; ansic: 628,724; xml: 44,704; fortran: 34,250; python: 22,874; sh: 4,078; pascal: 2,636; lisp: 2,158; makefile: 464; yacc: 328; asm: 205; perl: 203; lex: 146; tcl: 132; javascript: 98; csh: 81
file content (167 lines) | stat: -rw-r--r-- 5,026 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*=========================================================================
 *
 *  Copyright NumFOCUS
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         https://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#include "itkFastMarchingQuadEdgeMeshFilterBase.h"
#include "itkQuadEdgeMeshExtendedTraits.h"
#include "itkFastMarchingThresholdStoppingCriterion.h"
#include "itkMeshFileWriter.h"

int
itkFastMarchingQuadEdgeMeshFilterBaseTest2(int, char *[])
{
  using PixelType = float;
  using CoordType = double;

  constexpr unsigned int Dimension = 3;

  using Traits = itk::QuadEdgeMeshExtendedTraits<PixelType, // type of data for vertices
                                                 Dimension, // geometrical dimension of space
                                                 2,         // Mac topological dimension of a cell
                                                 CoordType, // type for point coordinate
                                                 CoordType, // type for interpolation weight
                                                 PixelType, // type of data for cell
                                                 bool,      // type of data for primal edges
                                                 bool       // type of data for dual edges
                                                 >;

  using MeshType = itk::QuadEdgeMesh<PixelType, Dimension, Traits>;

  using FastMarchingType = itk::FastMarchingQuadEdgeMeshFilterBase<MeshType, MeshType>;

  using MeshType = FastMarchingType::InputMeshType;

  using PointsContainer = MeshType::PointsContainer;
  using PointsContainerPointer = PointsContainer::Pointer;

  using PointDataContainer = MeshType::PointDataContainer;
  using PointDataContainerPointer = PointDataContainer::Pointer;

  // Let's create here a plane!
  auto plane = MeshType::New();

  PointsContainerPointer    points = PointsContainer::New();
  PointDataContainerPointer pointdata = PointDataContainer::New();

  points->Reserve(100);
  pointdata->Reserve(100);

  MeshType::PointType p;
  p[2] = 0.;

  int k = 0;

  for (int i = 0; i < 10; ++i)
  {
    p[0] = static_cast<CoordType>(i);

    for (int j = 0; j < 10; ++j)
    {
      p[1] = static_cast<CoordType>(j);
      points->SetElement(k, p);
      pointdata->SetElement(k, 1.);
      k++;
    }
  }

  plane->SetPoints(points);
  plane->SetPointData(pointdata);

  k = 0;

  for (int i = 0; i < 9; ++i)
  {
    for (int j = 0; j < 9; ++j)
    {
      plane->AddFaceTriangle(k, k + 1, k + 11);
      plane->AddFaceTriangle(k, k + 11, k + 10);
      k++;
    }
    k++;
  }

  using NodePairType = FastMarchingType::NodePairType;
  //  using NodeContainerType = FastMarchingType::NodeContainerType;
  using NodePairContainerType = FastMarchingType::NodePairContainerType;

  auto trial = NodePairContainerType::New();

  NodePairType node_pair(0, 0.);
  trial->push_back(node_pair);

  using CriterionType = itk::FastMarchingThresholdStoppingCriterion<MeshType, MeshType>;
  auto criterion = CriterionType::New();
  criterion->SetThreshold(100.);

  auto fmm_filter = FastMarchingType::New();
  fmm_filter->SetInput(plane);
  fmm_filter->SetTrialPoints(trial);
  fmm_filter->SetStoppingCriterion(criterion);

  try
  {
    fmm_filter->Update();
  }
  catch (const itk::ExceptionObject & excep)
  {
    std::cerr << "Exception caught !" << std::endl;
    std::cerr << excep << std::endl;
    return EXIT_FAILURE;
  }

  MeshType::Pointer output = fmm_filter->GetOutput();

  PointDataContainerPointer output_data = output->GetPointData();

  PointDataContainer::ConstIterator o_data_it = output_data->Begin();
  PointDataContainer::ConstIterator o_data_end = output_data->End();

  PointsContainer::ConstIterator p_it = points->Begin();

  p.Fill(0.);

  bool error = false;

  while (o_data_it != o_data_end)
  {
    PixelType expected_value = p.EuclideanDistanceTo(p_it->Value());

    if ((o_data_it->Value() - expected_value) > 5. * expected_value / 100.)
    {
      std::cout << "** k = " << k << std::endl;
      std::cout << o_data_it->Value() << " != " << expected_value << std::endl;
      error = true;
    }
    ++p_it;
    ++o_data_it;
  }

  using WriterType = itk::MeshFileWriter<MeshType>;
  auto writer = WriterType::New();
  writer->SetInput(output);
  writer->SetFileName("itkFastMarchingQuadEdgeMeshFilterBaseTest2.vtk");
  writer->Update();

  if (error)
  {
    return EXIT_FAILURE;
  }
  else
  {
    return EXIT_SUCCESS;
  }
}