32 #include "DGtal/base/Common.h"
33 #include "DGtal/kernel/SpaceND.h"
34 #include "DGtal/kernel/domains/HyperRectDomain.h"
35 #include "DGtal/images/ImageContainerByITKImage.h"
36 #include <boost/foreach.hpp>
40 #pragma GCC diagnostic push
41 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
43 #if defined(__clang__)
44 #pragma clang diagnostic push
45 #pragma clang diagnostic ignored "-Wdocumentation"
47 #include <itkExtractImageFilter.h>
48 #if defined(__clang__)
49 #pragma clang diagnostic pop
52 #pragma GCC diagnostic pop
58 using namespace DGtal;
69 unsigned int nbok = 0;
81 const Integer t[ ] = { 1, 1, 1};
82 const Integer t2[ ] = { 5, 5, 5};
83 const Integer t3[ ] = { 2, 2, 2};
84 Point lowerBound ( t );
85 Point upperBound ( t2 );
92 trace.
info() <<
"getvalue= " << myImage(c) << endl;
100 trace.
info() <<
"getvalue= " << val << endl;
125 auto & container = myImage.container();
129 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
130 <<
"true == true" << std::endl;
138 unsigned int nbok = 0;
151 Point lowerBound ( 0, 0 );
152 Point upperBound ( 9, 9);
174 typedef itk::ExtractImageFilter< Image::ITKImage, Image::ITKImage > CropFilter;
177 Image::ITKImage::SizeType size;
181 Image::ITKImage::IndexType
index;
185 Image::ITKImage::RegionType regionToExtract(index,size);
188 CropFilter::Pointer cropFilter = CropFilter::New();
189 cropFilter->SetInput( myImage.getITKImagePointer() );
190 cropFilter->SetExtractionRegion( regionToExtract );
191 cropFilter->Update();
194 Image::ITKImagePointer handleOut = cropFilter->GetOutput();
195 Image myImageOut ( handleOut );
204 nbok += (it.Value() == (it.GetIndex()[1]*10 + it.GetIndex()[0]));
206 trace.
warning() << it.Value() <<
"(" << (it.GetIndex()[1]*10 + it.GetIndex()[0]) <<
")" <<
" ";
210 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"true == true" << std::endl;
213 return nbok == 25 && nb == 25;
220 unsigned int nbok = 0;
232 const Integer t[ ] = { 1, 1, 1};
233 const Integer t2[ ] = { 5, 5, 5};
234 const Integer t3[ ] = { 2, 2, 2};
235 Point lowerBound ( t );
236 Point upperBound ( t2 );
248 auto itk_image = myImage.getITKImagePointer();
249 Image::ITKImage::PointType origin;
251 Image::ITKImage::SpacingType spacing;
253 Image::ITKImage::DirectionType direction;
254 direction.SetIdentity();
255 itk_image->SetOrigin(origin);
256 itk_image->SetSpacing(spacing);
257 itk_image->SetDirection(direction);
260 val = myImage.operator()(lowerBound);
261 nbok += (val == 0); nb++;
262 trace.
info() <<
"Index: " << lowerBound <<
". Value: " << val <<
". Expected: " << 0 << std::endl;
263 val = myImage.operator()(upperBound);
264 nbok += (val == 124); nb++;
265 trace.
info() <<
"Index: " << upperBound <<
". Value: " << val <<
". Expected: " << 124 << std::endl;
266 val = myImage.operator()(c);
267 nbok += (val == 31); nb++;
268 trace.
info() <<
"Index: " << c <<
". Value: " << val <<
". Expected: " << 31 << std::endl;
270 Image::PhysicalPoint physical_point;
271 Image::PhysicalPoint expected_physical_point;
275 index_point = myImage.getIndexFromDomainPoint(lowerBound);
276 nbok += (index_point == lowerBound); nb++;
277 physical_point = myImage.getPhysicalPointFromDomainPoint(index_point);
278 expected_physical_point = myImage.getLowerBoundAsPhysicalPoint();
279 nbok += (physical_point[0] == 12.0); nb++;
280 nbok += (physical_point == expected_physical_point); nb++;
281 trace.
info() <<
"Index: " << index_point <<
". PhysicalPoint: " << physical_point <<
". Expected: " << expected_physical_point << std::endl;
283 index_point = myImage.getIndexFromDomainPoint(upperBound);
284 nbok += (index_point == upperBound); nb++;
285 physical_point = myImage.getPhysicalPointFromDomainPoint(index_point);
286 expected_physical_point = myImage.getUpperBoundAsPhysicalPoint();
287 nbok += (physical_point[0] == 20.0); nb++;
288 nbok += (physical_point == expected_physical_point); nb++;
289 trace.
info() <<
"Index: " << index_point <<
". PhysicalPoint: " << physical_point <<
". Expected: " << expected_physical_point << std::endl;
291 auto index_back = myImage.getDomainPointFromPhysicalPoint(physical_point);
292 nbok += (index_back == upperBound); nb++;
293 trace.
info() <<
"PhysicalPoint: " << physical_point <<
". Index (back): " << index_back <<
". Expected: " << upperBound << std::endl;
297 return nbok == 10 && nb == 10;
304 unsigned int nbok = 0;
314 const Integer t[ ] = { 1, 1, 1};
315 const Integer t2[ ] = { 5, 5, 5};
316 const Integer t3[ ] = { 2, 2, 2};
317 Point lowerBound ( t );
318 Point upperBound ( t2 );
332 auto itk_image = myImage.getITKImagePointer();
333 Image::ITKImage::PointType origin;
335 Image::ITKImage::SpacingType spacing;
337 Image::ITKImage::DirectionType direction;
338 direction.SetIdentity();
339 itk_image->SetOrigin(origin);
340 itk_image->SetSpacing(spacing);
341 itk_image->SetDirection(direction);
345 const Integer sd[ ] = { -20, -20, -20};
346 Point domainShift(sd);
347 myImage.updateDomain(domainShift);
348 Point new_lowerBound = myImage.
domain().lowerBound();
349 Point new_upperBound = myImage.
domain().upperBound();
350 nbok += ( new_lowerBound == lowerBound + domainShift); nb++;
351 trace.
info() <<
"lowerBound: " << new_lowerBound <<
". Expected: " << lowerBound + domainShift << std::endl;
352 nbok += ( new_upperBound == upperBound + domainShift); nb++;
353 trace.
info() <<
"upperBound: " << new_upperBound <<
". Expected: " << upperBound + domainShift << std::endl;
356 val = myImage.operator()(new_lowerBound);
358 nbok += (val == 0); nb++;
359 trace.
info() <<
"Index: " << new_lowerBound <<
". Value: " << val <<
". Expected: " << 0 << std::endl;
360 val = myImage.operator()(new_upperBound);
361 nbok += (val == 124); nb++;
362 trace.
info() <<
"Index: " << new_upperBound <<
". Value: " << val <<
". Expected: " << 124 << std::endl;
363 val = myImage.operator()(myImage.getDomainPointFromIndex(c));
364 nbok += (val == 31); nb++;
365 trace.
info() <<
"Index: " << c <<
". Value: " << val <<
". Expected: " << 31 << std::endl;
367 Image::PhysicalPoint physical_point;
368 Image::PhysicalPoint expected_physical_point;
372 index_point = lowerBound;
373 domain_point = new_lowerBound;
374 physical_point = myImage.getPhysicalPointFromDomainPoint(domain_point);
375 expected_physical_point = Image::PhysicalPoint(12.0, 12.0, 12.0);
376 nbok += (physical_point == expected_physical_point); nb++;
377 trace.
info() <<
"Domain: " << domain_point <<
378 ". Index: " << index_point <<
379 ". PhysicalPoint: " << physical_point <<
380 ". Expected: " << expected_physical_point << std::endl;
382 index_point = myImage.getIndexFromDomainPoint(new_lowerBound);
383 nbok += ( index_point == lowerBound ); nb++;
384 trace.
info() <<
"index_point: " << index_point <<
". Expected: " << lowerBound << std::endl;
385 physical_point = myImage.getPhysicalPointFromDomainPoint(new_lowerBound);
386 expected_physical_point = myImage.getLowerBoundAsPhysicalPoint();
387 nbok += (physical_point[0] == 12.0); nb++;
388 nbok += (physical_point == expected_physical_point); nb++;
389 trace.
info() <<
"Domain: " << new_lowerBound <<
390 ". Index: " << index_point <<
391 ". PhysicalPoint: " << physical_point <<
392 ". Expected: " << expected_physical_point << std::endl;
394 index_point = upperBound;
395 domain_point = new_upperBound;
396 physical_point = myImage.getPhysicalPointFromDomainPoint(domain_point);
397 expected_physical_point = myImage.getUpperBoundAsPhysicalPoint();
398 nbok += (physical_point[0] == 20.0); nb++;
399 nbok += (physical_point == expected_physical_point); nb++;
400 trace.
info() <<
"Domain: " << new_lowerBound <<
401 ". Index: " << index_point <<
402 ". PhysicalPoint: " << physical_point <<
403 ". Expected: " << expected_physical_point << std::endl;
405 return nbok == 11 && nb == 11;
411 int main(
int argc,
char** argv )
415 for (
int i = 0; i < argc; ++i )
421 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: implements a model of CImageContainer using a ITK Image.
std::vector< Value >::const_iterator ConstIterator
std::vector< Value >::iterator Iterator
Aim: implements association bewteen points lying in a digital domain and values.
const Domain & domain() const
void setValue(const Point &aPoint, const Value &aValue)
void beginBlock(const std::string &keyword="")
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int32_t int32_t
signed 32-bit integer.
unsigned int index(DGtal::uint32_t n, unsigned int b)
SpaceND< 2, int > Space2Type
int main(int argc, char **argv)
bool testITKImageWithShiftDomain()
bool testITKImageWithMetadata()
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain