/usr/include/VTKEdge/vtkKWEPaintbrushUtilities.h is in libvtkedge-dev 0.2.0~20110819-1build2.
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 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 339 340 341 342 343 344 345 346 347 348 349 350 | //=============================================================================
// This file is part of VTKEdge. See vtkedge.org for more information.
//
// Copyright (c) 2010 Kitware, Inc.
//
// VTKEdge may be used under the terms of the BSD License
// Please see the file Copyright.txt in the root directory of
// VTKEdge for further information.
//
// Alternatively, you may see:
//
// http://www.vtkedge.org/vtkedge/project/license.html
//
//
// For custom extensions, consulting services, or training for
// this or any other Kitware supported open source project, please
// contact Kitware at sales@kitware.com.
//
//
//=============================================================================
// .NAME vtkKWEPaintbrushUtilities - helper class to cram unrelated functions.
// .SECTION Description
// Helper class to cram unclassifiable functions..
//
// All methods here are of course static
#ifndef __vtkKWEPaintbrushUtilities_h
#define __vtkKWEPaintbrushUtilities_h
#include "VTKEdgeConfigure.h" // needed for export symbols directives
#include "vtkObject.h"
#include "vtkImageData.h"
#include "vtkImageStencilData.h"
#include "vtkKWEPaintbrushStencilData.h"
#include "vtkKWEPaintbrushLabelData.h"
#include "vtkImageIterator.h"
#include "vtkSmartPointer.h"
#include <vtkstd/map>
#include <vtkstd/vector>
class vtkImageData;
class vtkImageStencilData;
class VTKEdge_WIDGETS_EXPORT vtkKWEPaintbrushUtilities: public vtkObject
{
public:
static vtkKWEPaintbrushUtilities * New();
vtkTypeRevisionMacro(vtkKWEPaintbrushUtilities, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Returns 0 if the extents don't intersect, 1 if they do interesect
// extent contains the intersection of extent1 and extent2.
static int GetIntersectingExtents( int extent1[6], int extent2[6],
int extent[6]);
//BTX
// Description:
// These functors provide the ability to do boolean operations on input data
// so as to convert imagedata to segmentations. They can be used to create
// multiple stencils from a label-map, by saying
// vtkImageStencilData *s1 = vtkImageStencilData::New();
// vtkImageStencilData *s2 = vtkImageStencilData::New();
// vtkImageStencilData *s3 = vtkImageStencilData::New();
// GetStencilFromImage< vtkFunctorEqualTo >( labelMapImage, s1, 64.0 );
// GetStencilFromImage< vtkFunctorEqualTo >( labelMapImage, s2, 128.0 );
// GetStencilFromImage< vtkFunctorEqualTo >( labelMapImage, s3, 192.0 );
class vtkFunctorEqualTo
{
public:
inline bool operator()( const double &a, const double &b )
{ return (a == b); }
};
class vtkFunctorGreaterThanEqualTo
{
public:
inline bool operator()( const double &a, const double &b )
{ return (a >= b); }
};
class vtkFunctorGreaterThan
{
public:
inline bool operator()( const double &a, const double &b )
{ return (a > b); }
};
class vtkFunctorLessThan
{
public:
inline bool operator()( const double &a, const double &b )
{ return (a < b); }
};
class vtkFunctorLessThanEqualTo
{
public:
inline bool operator()( const double &a, const double &b )
{ return (a < b); }
};
template < class TFunctor, class T >
static void vtkKWEPaintbrushUtilitiesGetStencilFromImage( vtkImageData *image,
vtkImageStencilData *stencilData, T threshold)
{
TFunctor f;
int extent[6];
double spacing[3], origin[3];
image->GetExtent(extent);
image->GetSpacing(spacing);
image->GetOrigin(origin);
stencilData->SetExtent(extent);
stencilData->SetSpacing(spacing);
stencilData->SetOrigin(origin);
stencilData->AllocateExtents();
vtkImageIterator< T > it(image, extent);
int ends[2], index[3];
index[1] = extent[2];
index[2] = extent[4];
while( !it.IsAtEnd() )
{
T *inSI = it.BeginSpan();
T *inSIEnd = it.EndSpan();
index[0] = extent[0];
ends[0] = -1;
ends[1] = -1;
if (f(static_cast<double>(*inSI), static_cast<double>(threshold)))
{
ends[0] = extent[0];
}
// for each row
while (inSI != inSIEnd)
{
if (ends[0] == -1 &&
f(static_cast<double>(*inSI), static_cast<double>(threshold)))
{
// look for start
ends[0] = index[0];
++index[0];
++inSI;
continue;
}
if (ends[0] != -1 && ends[1] == -1 &&
!f(static_cast<double>(*inSI), static_cast<double>(threshold)))
{
ends[1] = index[0];
stencilData->InsertNextExtent(ends[0], ends[1]-1, index[1], index[2]);
ends[0] = ends[1] = -1;
}
++index[0];
++inSI;
}
if (f(static_cast<double>(*(inSI-1)),
static_cast<double>(threshold))) // ends[0] can't be -1, ends[1] has to be -1
{
stencilData->InsertNextExtent(ends[0], extent[1], index[1], index[2]);
}
it.NextSpan();
if (index[1] == extent[3])
{
++index[2];
index[1] = extent[2];
}
else
{
++index[1];
}
}
}
template< class T >
static vtkstd::map< vtkKWEPaintbrushEnums::LabelType,
vtkSmartPointer< vtkKWEPaintbrushStencilData > >
vtkKWEPaintbrushUtilitiesGetStencilsFromImage(
vtkImageData *image,
vtkstd::vector< vtkKWEPaintbrushEnums::LabelType > labels,
T )
{
int extent[6];
double spacing[3], origin[3];
image->GetExtent(extent);
image->GetSpacing(spacing);
image->GetOrigin(origin);
vtkstd::map< vtkKWEPaintbrushEnums::LabelType,
vtkSmartPointer< vtkKWEPaintbrushStencilData > > pstrokeDatas;
vtkstd::map< vtkKWEPaintbrushEnums::LabelType,
vtkSmartPointer< vtkImageStencilData > > strokeDatas;
for (vtkstd::vector< vtkKWEPaintbrushEnums::LabelType >::const_iterator lit = labels.begin();
lit != labels.end(); ++lit)
{
vtkKWEPaintbrushEnums::LabelType l = *lit;
pstrokeDatas[l] = vtkSmartPointer< vtkKWEPaintbrushStencilData >::New();
pstrokeDatas[l]->SetLabel(*lit);
pstrokeDatas[l]->SetExtent(extent);
pstrokeDatas[l]->SetSpacing(spacing);
pstrokeDatas[l]->SetOrigin(origin);
pstrokeDatas[l]->Allocate();
strokeDatas[l] = pstrokeDatas[l]->GetImageStencilData();
}
vtkImageIterator< T > it(image, extent);
int ends[2], index[3];
index[1] = extent[2];
index[2] = extent[4];
vtkKWEPaintbrushEnums::LabelType label = vtkKWEPaintbrushLabelData::NoLabelValue;
while( !it.IsAtEnd() )
{
T *inSI = it.BeginSpan();
T *inSIEnd = it.EndSpan();
index[0] = extent[0];
ends[0] = -1;
ends[1] = -1;
// for each row
while (inSI != inSIEnd)
{
if (ends[0] == -1 && *inSI != vtkKWEPaintbrushLabelData::NoLabelValue)
{
// look for start
ends[0] = index[0];
++index[0];
label = static_cast< vtkKWEPaintbrushEnums::LabelType >(*inSI);
++inSI;
continue;
}
if (ends[0] != -1 && ends[1] == -1 && *inSI != label)
{
ends[1] = index[0];
strokeDatas[label]->InsertNextExtent(ends[0], ends[1]-1, index[1], index[2]);
ends[0] = ends[1] = -1;
if (*inSI != vtkKWEPaintbrushLabelData::NoLabelValue)
{
ends[0] = index[0];
label = static_cast< vtkKWEPaintbrushEnums::LabelType >(*inSI);
}
}
++index[0];
++inSI;
}
if (ends[0] != -1 && ends[1] == -1) // ends[0] can't be -1, ends[1] has to be -1
{
strokeDatas[label]->InsertNextExtent(ends[0], extent[1], index[1], index[2]);
}
it.NextSpan();
if (index[1] == extent[3])
{
++index[2];
index[1] = extent[2];
}
else
{
++index[1];
}
}
return pstrokeDatas;
}
// Description:
// Get a binary stencil from an image. All pixels <FUNCTOR> threshold are
// considered within the stencil.
//
// TFunctor may be any of the above defined class templates or your own.
// It may be any one of <= == >= > < operators.
// It should be a templated class that will provide a mechanism of
// comparing with the threshold and return a boolean. Common templates
// for greater-than / less-than etc are already provided.
template < class TFunctor >
static void GetStencilFromImage( vtkImageData * image,
vtkImageStencilData * stencilData,
double threshold )
{
switch (image->GetScalarType())
{
vtkTemplateMacro( vtkKWEPaintbrushUtilitiesGetStencilFromImage< TFunctor >(
image, stencilData, static_cast<VTK_TT>(threshold)));
}
}
static vtkstd::map< vtkKWEPaintbrushEnums::LabelType,
vtkSmartPointer< vtkKWEPaintbrushStencilData > >
GetStencilsFromImage( vtkImageData * image,
vtkstd::vector< vtkKWEPaintbrushEnums::LabelType > labels)
{
typedef vtkstd::map< vtkKWEPaintbrushEnums::LabelType,
vtkSmartPointer< vtkKWEPaintbrushStencilData > > StrokeToLabelMapType;
StrokeToLabelMapType r;
switch (image->GetScalarType())
{
vtkTemplateMacro( (r =
vtkKWEPaintbrushUtilitiesGetStencilsFromImage(
image, labels, static_cast<VTK_TT>(0))));
}
return r;
}
// Description:
// Populate a vtkImageData from a binary stencil.
// "inVal" and "outVal" define the values assigned to the image inside and
// outside the object. If "UseImageExtent" is true, the image extents are
// preserved. If not, the image acquires its metadata from the stencil.
static void GetImageFromStencil( vtkImageData *,
vtkImageStencilData *,
unsigned char inVal,
unsigned char outVal,
bool UseImageExtent = false );
//ETX
// Description:
// Check if one extent is equal to the other extent. Returns 1 if true.
static int ExtentIsEqualToExtent( int e1[6], int e2[6] );
protected:
vtkKWEPaintbrushUtilities();
~vtkKWEPaintbrushUtilities();
private:
vtkKWEPaintbrushUtilities(const vtkKWEPaintbrushUtilities &); // Not implemented
void operator=(const vtkKWEPaintbrushUtilities &); // Not implemented
};
#endif
|