/usr/include/InsightToolkit/SpatialObject/itkMetaContourConverter.txx is in libinsighttoolkit3-dev 3.20.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkMetaContourConverter.txx
Language: C++
Date: $Date$
Version: $Revision$
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 __itkMetaContourConverter_txx
#define __itkMetaContourConverter_txx
#include "itkMetaContourConverter.h"
namespace itk
{
/** Constructor */
template <unsigned int NDimensions>
MetaContourConverter<NDimensions>
::MetaContourConverter()
{
}
/** Convert a metaContour into an Contour SpatialObject */
template <unsigned int NDimensions>
typename MetaContourConverter<NDimensions>::SpatialObjectPointer
MetaContourConverter<NDimensions>
::MetaContourToContourSpatialObject(MetaContour * Contour)
{
typedef itk::ContourSpatialObject<NDimensions> ContourSpatialObjectType;
typename ContourSpatialObjectType::Pointer contour =
ContourSpatialObjectType::New();
double spacing[NDimensions];
unsigned int ndims = Contour->NDims();
for(unsigned int i=0;i<ndims;i++)
{
spacing[i]=Contour->ElementSpacing()[i];
}
contour->GetIndexToObjectTransform()->SetScaleComponent(spacing);
contour->GetProperty()->SetName(Contour->Name());
contour->SetId(Contour->ID());
contour->SetParentId(Contour->ParentID());
contour->GetProperty()->SetRed(Contour->Color()[0]);
contour->GetProperty()->SetGreen(Contour->Color()[1]);
contour->GetProperty()->SetBlue(Contour->Color()[2]);
contour->GetProperty()->SetAlpha(Contour->Color()[3]);
contour->SetClosed(Contour->Closed());
contour->SetAttachedToSlice(Contour->AttachedToSlice());
contour->SetDisplayOrientation(Contour->DisplayOrientation());
// First the control points
typedef typename ContourSpatialObjectType::ControlPointType ControlPointType;
typedef MetaContour::ControlPointListType ControlListType;
ControlListType::iterator itCP = Contour->GetControlPoints().begin();
for(unsigned int identifier=0;identifier< Contour->GetControlPoints().size();identifier++)
{
ControlPointType pnt;
typedef typename ControlPointType::PointType PointType;
PointType point;
PointType pickedPoint;
typedef typename ControlPointType::VectorType VectorType;
VectorType normal;
for(unsigned int i=0;i<ndims;i++)
{
point[i]=(*itCP)->m_X[i];
}
for(unsigned int i=0;i<ndims;i++)
{
pickedPoint[i]=(*itCP)->m_XPicked[i];
}
for(unsigned int i=0;i<ndims;i++)
{
normal[i]=(*itCP)->m_V[i];
}
pnt.SetID((*itCP)->m_Id);
pnt.SetRed((*itCP)->m_Color[0]);
pnt.SetGreen((*itCP)->m_Color[1]);
pnt.SetBlue((*itCP)->m_Color[2]);
pnt.SetAlpha((*itCP)->m_Color[3]);
pnt.SetPosition(point);
pnt.SetPickedPoint(pickedPoint);
pnt.SetNormal(normal);
contour->GetControlPoints().push_back(pnt);
itCP++;
}
// Then the interpolated points
typedef typename ContourSpatialObjectType::InterpolatedPointType
InterpolatedPointType;
typedef MetaContour::InterpolatedPointListType InterpolatedListType;
InterpolatedListType::iterator itI = Contour->GetInterpolatedPoints().begin();
for(unsigned int identifier=0;identifier< Contour->GetInterpolatedPoints().size();identifier++)
{
InterpolatedPointType pnt;
typedef typename ControlPointType::PointType PointType;
PointType point;
typedef typename ControlPointType::VectorType VectorType;
VectorType normal;
for(unsigned int i=0;i<ndims;i++)
{
point[i]=(*itI)->m_X[i];
}
pnt.SetID((*itI)->m_Id);
pnt.SetRed((*itI)->m_Color[0]);
pnt.SetGreen((*itI)->m_Color[1]);
pnt.SetBlue((*itI)->m_Color[2]);
pnt.SetAlpha((*itI)->m_Color[3]);
pnt.SetPosition(point);
contour->GetInterpolatedPoints().push_back(pnt);
itI++;
}
return contour;
}
/** Convert an Contour SpatialObject into a metaContour */
template <unsigned int NDimensions>
MetaContour*
MetaContourConverter<NDimensions>
::ContourSpatialObjectToMetaContour(SpatialObjectType * spatialObject)
{
MetaContour* Contour = new MetaContour(NDimensions);
// fill in the control points information
typename SpatialObjectType::ControlPointListType::const_iterator itCP;
for(itCP = dynamic_cast<SpatialObjectType*>(spatialObject)->GetControlPoints().begin();
itCP != dynamic_cast<SpatialObjectType*>(spatialObject)->GetControlPoints().end();
itCP++)
{
ContourControlPnt* pnt = new ContourControlPnt(NDimensions);
pnt->m_Id = (*itCP).GetID();
for(unsigned int d=0;d<NDimensions;d++)
{
pnt->m_X[d]=(*itCP).GetPosition()[d];
}
for(unsigned int d=0;d<NDimensions;d++)
{
pnt->m_XPicked[d]=(*itCP).GetPickedPoint()[d];
}
for(unsigned int d=0;d<NDimensions;d++)
{
pnt->m_V[d]=(*itCP).GetNormal()[d];
}
pnt->m_Color[0] = (*itCP).GetRed();
pnt->m_Color[1] = (*itCP).GetGreen();
pnt->m_Color[2] = (*itCP).GetBlue();
pnt->m_Color[3] = (*itCP).GetAlpha();
Contour->GetControlPoints().push_back(pnt);
}
if(NDimensions == 2)
{
Contour->ControlPointDim("id x y xp yp v1 v2 r g b a");
}
else if (NDimensions == 3)
{
Contour->ControlPointDim("id x y z xp yp zp v1 v2 v3 r gn be a");
}
// fill in the interpolated points information
typename SpatialObjectType::InterpolatedPointListType::const_iterator itI;
for(itI = dynamic_cast<SpatialObjectType*>(spatialObject)->GetInterpolatedPoints().begin();
itI != dynamic_cast<SpatialObjectType*>(spatialObject)->GetInterpolatedPoints().end();
itI++)
{
ContourInterpolatedPnt* pnt = new ContourInterpolatedPnt(NDimensions);
pnt->m_Id = (*itI).GetID();
for(unsigned int d=0;d<NDimensions;d++)
{
pnt->m_X[d]=(*itI).GetPosition()[d];
}
pnt->m_Color[0] = (*itI).GetRed();
pnt->m_Color[1] = (*itI).GetGreen();
pnt->m_Color[2] = (*itI).GetBlue();
pnt->m_Color[3] = (*itI).GetAlpha();
Contour->GetInterpolatedPoints().push_back(pnt);
}
if(NDimensions == 2)
{
Contour->InterpolatedPointDim("id x y r g b a");
}
else if (NDimensions == 3)
{
Contour->InterpolatedPointDim("id x y z r g b a");
}
// Set the interpolation type
switch(spatialObject->GetInterpolationType())
{
case SpatialObjectType::EXPLICIT_INTERPOLATION :
Contour->Interpolation(MET_EXPLICIT_INTERPOLATION);
break;
case SpatialObjectType::LINEAR_INTERPOLATION :
Contour->Interpolation(MET_LINEAR_INTERPOLATION);
break;
case SpatialObjectType::BEZIER_INTERPOLATION :
Contour->Interpolation(MET_BEZIER_INTERPOLATION);
break;
default:
Contour->Interpolation(MET_NO_INTERPOLATION);
}
float color[4];
for(unsigned int i=0;i<4;i++)
{
color[i]=spatialObject->GetProperty()->GetColor()[i];
}
Contour->Color(color);
Contour->ID( spatialObject->GetId());
Contour->Closed(spatialObject->GetClosed());
Contour->AttachedToSlice(spatialObject->GetAttachedToSlice());
Contour->DisplayOrientation(spatialObject->GetDisplayOrientation());
if(spatialObject->GetParent())
{
Contour->ParentID(spatialObject->GetParent()->GetId());
}
for(unsigned int i=0;i<NDimensions;i++)
{
Contour->ElementSpacing(i, spatialObject->GetIndexToObjectTransform()
->GetScaleComponent()[i]);
}
return Contour;
}
/** Read a meta file give the type */
template <unsigned int NDimensions>
typename MetaContourConverter<NDimensions>::SpatialObjectPointer
MetaContourConverter<NDimensions>
::ReadMeta(const char* name)
{
SpatialObjectPointer spatialObject;
MetaContour* Contour = new MetaContour();
Contour->Read(name);
spatialObject = MetaContourToContourSpatialObject(Contour);
return spatialObject;
}
/** Write a meta Contour file */
template <unsigned int NDimensions>
bool
MetaContourConverter<NDimensions>
::WriteMeta(SpatialObjectType* spatialObject,const char* name)
{
MetaContour* Contour = ContourSpatialObjectToMetaContour(spatialObject);
Contour->Write(name);
return true;
}
} // end namespace itk
#endif
|