Chaste  Build::
SurfaceCleaner.cpp
1 /*
2  Copyright (c) 2005-2015, University of Oxford.
3  All rights reserved.
4 
5  University of Oxford means the Chancellor, Masters and Scholars of the
6  University of Oxford, having an administrative office at Wellington
7  Square, Oxford OX1 2JD, UK.
8 
9  This file is part of Chaste.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are met:
13  * Redistributions of source code must retain the above copyright notice,
14  this list of conditions and the following disclaimer.
15  * Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18  * Neither the name of the University of Oxford nor the names of its
19  contributors may be used to endorse or promote products derived from this
20  software without specific prior written permission.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33  */
34 
35 #include <vtkDecimatePro.h>
36 #include <vtkLinearSubdivisionFilter.h>
37 #include "Exception.hpp"
38 #include "SurfaceCleaner.hpp"
39 
41  : mpInputSurface(),
42  mpOutputSurface(),
43  mDecimateTargetReduction(0.9994),
44  mDecimateFeatureAngle(15.0),
45  mLinearSubdivisionNumber(3)
46 {
47 
48 }
49 
50 boost::shared_ptr<SurfaceCleaner> SurfaceCleaner::Create()
51 {
52  MAKE_PTR(SurfaceCleaner, pSelf);
53  return pSelf;
54 }
55 
57 {
58 
59 }
60 
61 vtkSmartPointer<vtkPolyData> SurfaceCleaner::GetOutput()
62 {
63  if(mpOutputSurface)
64  {
65  return(mpOutputSurface);
66  }
67  else
68  {
69  EXCEPTION("No output set. Did you run 'Update()' ?");
70  }
71 }
72 
73 void SurfaceCleaner::SetInput(vtkSmartPointer<vtkPolyData> pInput)
74 {
75  mpInputSurface = pInput;
76 }
77 
79 {
81 }
82 
84 {
85  mDecimateFeatureAngle = value;
86 }
87 
89 {
91 }
92 
94 {
95  if(!mpInputSurface)
96  {
97  EXCEPTION("No input set.");
98  }
99 
100  vtkSmartPointer<vtkDecimatePro> p_decimate = vtkSmartPointer<vtkDecimatePro>::New();
101  #if VTK_MAJOR_VERSION <= 5
102  p_decimate->SetInput(mpInputSurface);
103  #else
104  p_decimate->SetInputData(mpInputSurface);
105  #endif
106  p_decimate->SetTargetReduction(mDecimateTargetReduction);
107  p_decimate->SetFeatureAngle(mDecimateFeatureAngle);
108  p_decimate->Update();
109 
110  vtkSmartPointer<vtkLinearSubdivisionFilter> p_divide = vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
111  p_divide->SetInputConnection(p_decimate->GetOutputPort());
112  p_divide->SetNumberOfSubdivisions(mLinearSubdivisionNumber);
113  p_divide->Update();
114 
115  mpOutputSurface = p_divide->GetOutput();
116 }
vtkSmartPointer< vtkPolyData > GetOutput()
double mDecimateTargetReduction
void SetDecimateTargetReduction(double value)
void SetInput(vtkSmartPointer< vtkPolyData > pInputSurface)
double mDecimateFeatureAngle
static boost::shared_ptr< SurfaceCleaner > Create()
void SetLinearSubdivisionNumber(double value)
unsigned mLinearSubdivisionNumber
vtkSmartPointer< vtkPolyData > mpOutputSurface
void SetDecimateFeatureAngle(double value)
vtkSmartPointer< vtkPolyData > mpInputSurface