/usr/include/ITK-4.5/itkMetaContourConverter.hxx is in libinsighttoolkit4-dev 4.5.0-3.
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 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* 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
*
* http://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.
*
*=========================================================================*/
#ifndef __itkMetaContourConverter_hxx
#define __itkMetaContourConverter_hxx
#include "itkMetaContourConverter.h"
namespace itk
{
/** Constructor */
template< unsigned int NDimensions >
MetaContourConverter< NDimensions >
::MetaContourConverter()
{}
template< unsigned int NDimensions >
typename MetaContourConverter< NDimensions >::MetaObjectType *
MetaContourConverter< NDimensions>
::CreateMetaObject()
{
return dynamic_cast<MetaObjectType *>(new ContourMetaObjectType);
}
/** Convert a metaContour into an Contour SpatialObject */
template< unsigned int NDimensions >
typename MetaContourConverter< NDimensions >::SpatialObjectPointer
MetaContourConverter< NDimensions >
::MetaObjectToSpatialObject(const MetaObjectType *mo)
{
const ContourMetaObjectType *contourMO = dynamic_cast<const MetaContour *>(mo);
if(contourMO == 0)
{
itkExceptionMacro(<< "Can't downcast MetaObject to MetaContour");
}
ContourSpatialObjectPointer contourSO =
ContourSpatialObjectType::New();
double spacing[NDimensions];
unsigned int ndims = contourMO->NDims();
for ( unsigned int i = 0; i < ndims; i++ )
{
spacing[i] = contourMO->ElementSpacing()[i];
}
contourSO->GetIndexToObjectTransform()->SetScaleComponent(spacing);
contourSO->GetProperty()->SetName( contourMO->Name() );
contourSO->SetId( contourMO->ID() );
contourSO->SetParentId( contourMO->ParentID() );
contourSO->GetProperty()->SetRed(contourMO->Color()[0]);
contourSO->GetProperty()->SetGreen(contourMO->Color()[1]);
contourSO->GetProperty()->SetBlue(contourMO->Color()[2]);
contourSO->GetProperty()->SetAlpha(contourMO->Color()[3]);
contourSO->SetClosed( const_cast<ContourMetaObjectType *>(contourMO)->Closed() );
contourSO->SetAttachedToSlice( const_cast<ContourMetaObjectType *>(contourMO)->AttachedToSlice() );
contourSO->SetDisplayOrientation( const_cast<ContourMetaObjectType *>(contourMO)->DisplayOrientation() );
// First the control points
typedef typename ContourSpatialObjectType::ControlPointType ControlPointType;
typename ContourMetaObjectType::ControlPointListType::const_iterator itCP =
contourMO->GetControlPoints().begin();
for ( unsigned int identifier = 0; identifier < contourMO->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);
contourSO->GetControlPoints().push_back(pnt);
itCP++;
}
// Then the interpolated points
typedef typename ContourSpatialObjectType::InterpolatedPointType InterpolatedPointType;
typename ContourMetaObjectType::InterpolatedPointListType::const_iterator
itI = contourMO->GetInterpolatedPoints().begin();
for ( unsigned int identifier = 0; identifier < contourMO->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);
contourSO->GetInterpolatedPoints().push_back(pnt);
itI++;
}
return contourSO.GetPointer();
}
/** Convert a Contour SpatialObject into a metaContour */
template< unsigned int NDimensions >
typename MetaContourConverter< NDimensions>::MetaObjectType *
MetaContourConverter< NDimensions >
::SpatialObjectToMetaObject(const SpatialObjectType *so)
{
ContourSpatialObjectConstPointer contourSO =
dynamic_cast<const ContourSpatialObjectType *>(so);
if(contourSO.IsNull())
{
itkExceptionMacro(<< "Can't downcast SpatialObject to ContourSpatialObject");
}
MetaContour *contourMO = new MetaContour(NDimensions);
// fill in the control points information
typename ContourSpatialObjectType::ControlPointListType::const_iterator itCP;
for ( itCP = contourSO->GetControlPoints().begin();
itCP != contourSO->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();
contourMO->GetControlPoints().push_back(pnt);
}
if ( NDimensions == 2 )
{
contourMO->ControlPointDim("id x y xp yp v1 v2 r g b a");
}
else if ( NDimensions == 3 )
{
contourMO->ControlPointDim("id x y z xp yp zp v1 v2 v3 r gn be a");
}
// fill in the interpolated points information
typename ContourSpatialObjectType::InterpolatedPointListType::const_iterator itI;
for ( itI = contourSO->GetInterpolatedPoints().begin();
itI != contourSO->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();
contourMO->GetInterpolatedPoints().push_back(pnt);
}
if ( NDimensions == 2 )
{
contourMO->InterpolatedPointDim("id x y r g b a");
}
else if ( NDimensions == 3 )
{
contourMO->InterpolatedPointDim("id x y z r g b a");
}
// Set the interpolation type
switch ( contourSO->GetInterpolationType() )
{
case ContourSpatialObjectType::EXPLICIT_INTERPOLATION:
contourMO->Interpolation(MET_EXPLICIT_INTERPOLATION);
break;
case ContourSpatialObjectType::LINEAR_INTERPOLATION:
contourMO->Interpolation(MET_LINEAR_INTERPOLATION);
break;
case ContourSpatialObjectType::BEZIER_INTERPOLATION:
contourMO->Interpolation(MET_BEZIER_INTERPOLATION);
break;
default:
contourMO->Interpolation(MET_NO_INTERPOLATION);
}
float color[4];
for ( unsigned int i = 0; i < 4; i++ )
{
color[i] = contourSO->GetProperty()->GetColor()[i];
}
contourMO->Color(color);
contourMO->ID( contourSO->GetId() );
contourMO->Closed( contourSO->GetClosed() );
contourMO->AttachedToSlice( contourSO->GetAttachedToSlice() );
contourMO->DisplayOrientation( contourSO->GetDisplayOrientation() );
if ( contourSO->GetParent() )
{
contourMO->ParentID( contourSO->GetParent()->GetId() );
}
for ( unsigned int i = 0; i < NDimensions; i++ )
{
contourMO->ElementSpacing(i, contourSO->GetIndexToObjectTransform()
->GetScaleComponent()[i]);
}
contourMO->BinaryData(true);
return contourMO;
}
} // end namespace itk
#endif
|