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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkSimplexMeshAdaptTopologyFilter.h,v $
Language: C++
Date: $Date: 2007-02-01 18:06:01 $
Version: $Revision: 1.11 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkSimplexMeshAdaptTopologyFilter_h
#define __itkSimplexMeshAdaptTopologyFilter_h
#include "itkMesh.h"
#include "itkPolygonCell.h"
#include "itkMapContainer.h"
#include "itkCellInterfaceVisitor.h"
#include "itkSimplexMesh.h"
#include "itkSimplexMeshGeometry.h"
#include "itkMeshToMeshFilter.h"
#include "itkVectorContainer.h"
#include <itkCovariantVector.h>
#include <vxl_version.h>
#if VXL_VERSION_DATE_FULL > 20040406
# include <vnl/vnl_cross.h>
# define itk_cross_3d vnl_cross_3d
#else
# define itk_cross_3d cross_3d
#endif
namespace itk
{
/** \class SimplexMeshAdaptTopologyFilter
* \brief This filter changes the topology of a 2-simplex mesh
*
* Currently only one transformation for inserting new cells into a mesh is implemented.
* For insertion several criteria are compute, e.g. the curvature in a mesh point. The user
* can set a threshold value to control how many cells will be manipulated.
*
* \author Thomas Boettger. Division Medical and Biological Informatics, German Cancer Research Center, Heidelberg.
*
*/
template <class TInputMesh, class TOutputMesh>
class SimplexMeshAdaptTopologyFilter : public MeshToMeshFilter<TInputMesh, TOutputMesh>
{
public:
/** Standard "Self" typedef. */
typedef SimplexMeshAdaptTopologyFilter Self;
/** Standard "Superclass" typedef. */
typedef MeshToMeshFilter<TInputMesh, TOutputMesh> Superclass;
/** Smart pointer typedef support */
typedef SmartPointer<Self> Pointer;
/** Smart pointer typedef support */
typedef SmartPointer<const Self> ConstPointer;
/** Method of creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(SimplexMeshAdaptTopologyFilter,MeshToMeshFilter);
typedef TInputMesh InputMeshType;
typedef typename InputMeshType::Pointer InputMeshPointer;
typedef typename InputMeshType::PointType InputPointType;
typedef typename InputMeshType::VectorType InputVectorType;
typedef typename InputMeshType::PixelType InputPixelType;
typedef typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType;
typedef typename InputMeshType::CellType InputCellType;
typedef typename InputCellType::PointIdIterator InputCellPointIdIterator;
typedef typename InputCellType::CellAutoPointer InputCellAutoPointer;
typedef typename InputMeshType::CellAutoPointer CellAutoPointer;
typedef itk::PolygonCell<InputCellType> InputPolygonType;
typedef typename InputPolygonType::PointIdIterator InputPolygonPointIdIterator;
typedef CovariantVector<
typename InputVectorType::ValueType, 3 > CovariantVectorType;
typedef TOutputMesh OutputMeshType;
typedef typename OutputMeshType::Pointer OutputMeshPointer;
typedef typename OutputMeshType::CellType OutputCellType;
typedef itk::PolygonCell<OutputCellType> OutputPolygonType;
typedef itk::MapContainer<unsigned long, double> DoubleValueMapType;
typedef typename DoubleValueMapType::Iterator DoubleContainerIterator;
/**
* class for visiting all polygonal cells.
* The visitor computes the area and curvature
* of each cell and stores them in the area
* map.
*/
class SimplexCellVisitor
{
public:
InputMeshPointer mesh;
double totalArea;
double totalCurvature;
double minCellSize;
double maxCellSize;
DoubleValueMapType::Pointer areaMap;
DoubleValueMapType::Pointer curvatureMap;
double minCurvature;
double maxCurvature;
SimplexCellVisitor()
{
areaMap = DoubleValueMapType::New();
curvatureMap = DoubleValueMapType::New();
totalArea = 0;
totalCurvature = 0;
minCellSize = NumericTraits<double>::max();
maxCellSize = 0;
minCurvature = NumericTraits<double>::max();
maxCurvature = 0;
}
/** \brief visits all polygon cells and computes the area,
* NOTE: works for convex polygons only!!!
*/
void Visit(unsigned long cellId, InputPolygonType * poly)
{
typename InputPolygonType::PointIdIterator it = poly->PointIdsBegin();
double meanCurvature = 0;
unsigned long refPoint = *it;
double val = mesh->GetMeanCurvature(*it++);
meanCurvature += vcl_abs(val);
unsigned long id1 = *it;
val = mesh->GetMeanCurvature(*it++);
meanCurvature += vcl_abs(val);
unsigned long id2;
double area = 0;
int cnt = 0;
while ( it != poly->PointIdsEnd() )
{
id2 = *it;
area += ComputeArea(refPoint,id1,id2);
id1 = id2;
val = mesh->GetMeanCurvature(*it);
meanCurvature += vcl_abs(val);
cnt++;
it++;
}
meanCurvature /= (double)cnt;
totalArea += area;
totalCurvature += meanCurvature;
areaMap->InsertElement(cellId, area);
curvatureMap->InsertElement(cellId, meanCurvature);
if (area > maxCellSize ) maxCellSize = area;
if (area < minCellSize ) minCellSize = area;
if (meanCurvature > maxCurvature ) maxCurvature = meanCurvature;
if (meanCurvature < minCurvature ) minCurvature = meanCurvature;
}
double ComputeArea(unsigned long p1,unsigned long p2, unsigned long p3)
{
InputPointType v1,v2,v3;
mesh->GetPoint(p1, &v1);
mesh->GetPoint(p2, &v2);
mesh->GetPoint(p3, &v3);
return vcl_abs (itk_cross_3d((v2-v1).GetVnlVector(), (v3-v1).GetVnlVector()).two_norm() /2.0);
}
DoubleValueMapType::Pointer GetAreaMap()
{
return areaMap;
}
DoubleValueMapType::Pointer GetCurvatureMap()
{
return curvatureMap;
}
double GetTotalMeshArea()
{
return totalArea;
}
double GetTotalMeanCurvature()
{
return totalCurvature/(curvatureMap->Size());
}
double GetMaximumCellSize()
{
return maxCellSize;
}
double GetMinimumCellSize()
{
return minCellSize;
}
double GetMaximumCurvature()
{
return maxCurvature;
}
double GetMinimumCurvature()
{
return minCurvature;
}
};
// cell visitor stuff
typedef itk::CellInterfaceVisitorImplementation<InputPixelType,
InputCellTraitsType,
InputPolygonType,
SimplexCellVisitor>
SimplexVisitorInterfaceType;
typedef typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer;
typedef typename InputCellType::MultiVisitor CellMultiVisitorType;
typedef typename CellMultiVisitorType::Pointer CellMultiVisitorPointer;
itkSetMacro(Threshold, double);
itkGetMacro(Threshold, double);
itkSetMacro(SelectionMethod, int);
itkGetMacro(SelectionMethod, int);
itkGetMacro(ModifiedCount, int);
protected:
SimplexMeshAdaptTopologyFilter();
~SimplexMeshAdaptTopologyFilter();
SimplexMeshAdaptTopologyFilter(const Self&)
{
}
void operator=(const Self&)
{
}
void PrintSelf(std::ostream& os, Indent indent) const;
virtual void GenerateData();
/**
* Initialize this filters containers
*/
void Initialize();
/**
* Method computes and evaluates cell propeties,
* like area and curvature and determines whether
* a cell should be refined or not.
*/
void ComputeCellParameters();
/**
* Create new cells
*/
void InsertNewCells();
/**
* Update topology neighbor relations for all cells
* which are were influenced by he insertion of new
* points.
*/
void ModifyNeighborCells(unsigned long id1, unsigned long id2, unsigned long insertPointId);
/**
* Compute the center of a cell
*/
InputPointType ComputeCellCenter(InputCellAutoPointer &simplexCell);
/**
* class member stoing cell id offset
*/
unsigned long m_IdOffset;
/**
* threshold controls the percentage of cells
* to satify the selection criteria
*/
double m_Threshold;
/**
* different criteria for cell refinement selection
*/
int m_SelectionMethod;
/**
* atttribute contains the number of cells
* which were modified during the last Update()
*/
int m_ModifiedCount;
/**
* \brief member for accessing the filter result during
* creation
*/
OutputMeshPointer m_Output;
InputCellAutoPointer NewSimplexCellPointer;
};
} //end of namespace
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkSimplexMeshAdaptTopologyFilter.txx"
#endif
#endif // __itkSimplexMeshAdaptTopologyFilter_h
|