Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support of Center-X/Y/Z for VolReader/Writer #879

Merged
merged 12 commits into from
Jul 13, 2014
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
ArithmeticalDSS) (Tristan Roussillon,
[#819](https:/DGtal-team/DGtal/pull/819))

- *IO Package*
- Now VolReader/VolWriter and LongvolReader/LongvolWriter support the
usage of Center-(X,Y,Z) parameters, as described in Vol file
specification. (Jérémy Levallois,
[#879](https:/DGtal-team/DGtal/pull/879))

- *Math Package*

- New classes to compute nD eigen decomposition of symmetric
Expand Down
31 changes: 23 additions & 8 deletions src/DGtal/io/readers/LongvolReader.ih
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ DGtal::LongvolReader<T, TFunctor>::importLongvol( const std::string & filename,
}

int sx = 0, sy = 0, sz=0;
int cx = 0, cy = 0, cz=0;

getHeaderValueAsInt( "X", &sx, header );
getHeaderValueAsInt( "Y", &sy, header );
Expand Down Expand Up @@ -179,19 +180,33 @@ DGtal::LongvolReader<T, TFunctor>::importLongvol( const std::string & filename,
}

//Raw Data
long count = 0;

firstPoint = T::Point::zero;
lastPoint[0] = sx - 1;
lastPoint[1] = sy - 1;
lastPoint[2] = sz - 1;

if( getHeaderValueAsInt( "Center-X", &cx, header ) == 0 )
{
getHeaderValueAsInt( "Center-Y", &cy, header );
getHeaderValueAsInt( "Center-Z", &cz, header );

firstPoint[0] = cx - (sx - 1)/2;
firstPoint[1] = cy - (sy - 1)/2;
firstPoint[2] = cz - (sz - 1)/2;
lastPoint[0] = cx + sx/2;
lastPoint[1] = cy + sy/2;
lastPoint[2] = cz + sz/2;
}
else
{
firstPoint = T::Point::zero;
lastPoint[0] = sx - 1;
lastPoint[1] = sy - 1;
lastPoint[2] = sz - 1;
}
typename T::Domain domain( firstPoint, lastPoint );

try
{
T image( domain);

count = 0;
long count = 0;
DGtal::uint64_t val=0;

typename T::Domain::ConstIterator it = domain.begin();
Expand Down Expand Up @@ -274,6 +289,6 @@ DGtal::LongvolReader<T, TFunctor>::getHeaderValueAsInt( const char *type, int *d
if ( i == -1 )
return 1;

return sscanf( header[i].value, "%d", dest ) != 0;
return sscanf( header[i].value, "%d", dest ) == 0;
}

2 changes: 1 addition & 1 deletion src/DGtal/io/readers/VolReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace DGtal
// ----------------------- Standard services ------------------------------

typedef TImageContainer ImageContainer;
typedef typename TImageContainer::Value Value;
typedef typename TImageContainer::Value Value;
typedef TFunctor Functor;

BOOST_CONCEPT_ASSERT(( CUnaryFunctor<TFunctor, unsigned char, Value > )) ;
Expand Down
30 changes: 23 additions & 7 deletions src/DGtal/io/readers/VolReader.ih
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ DGtal::VolReader<T, TFunctor>::importVol( const std::string & filename,
}

int sx = 0, sy= 0, sz= 0;
int cx = 0, cy= 0, cz= 0;

getHeaderValueAsInt( "X", &sx, header );
getHeaderValueAsInt( "Y", &sy, header );
Expand Down Expand Up @@ -191,19 +192,34 @@ DGtal::VolReader<T, TFunctor>::importVol( const std::string & filename,
}

//Raw Data
long count = 0;

firstPoint = T::Point::zero;
lastPoint[0] = sx - 1;
lastPoint[1] = sy - 1;
lastPoint[2] = sz - 1;
if( getHeaderValueAsInt( "Center-X", &cx, header ) == 0 )
{
getHeaderValueAsInt( "Center-Y", &cy, header );
getHeaderValueAsInt( "Center-Z", &cz, header );

firstPoint[0] = cx - (sx - 1)/2;
firstPoint[1] = cy - (sy - 1)/2;
firstPoint[2] = cz - (sz - 1)/2;
lastPoint[0] = cx + sx/2;
lastPoint[1] = cy + sy/2;
lastPoint[2] = cz + sz/2;
}
else
{
firstPoint = T::Point::zero;
lastPoint[0] = sx - 1;
lastPoint[1] = sy - 1;
lastPoint[2] = sz - 1;
}

typename T::Domain domain( firstPoint, lastPoint );

try
{
T image( domain );

count = 0;
long count = 0;
unsigned char val;
typename T::Domain::ConstIterator it = domain.begin();
long int total = sx * sy * sz;
Expand Down Expand Up @@ -285,6 +301,6 @@ DGtal::VolReader<T, TFunctor>::getHeaderValueAsInt( const char *type, int *dest
if ( i == -1 )
return 1;

return sscanf( header[i].value, "%d", dest ) != 0;
return sscanf( header[i].value, "%d", dest ) == 0;
}

10 changes: 8 additions & 2 deletions src/DGtal/io/writers/LongvolWriter.ih
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ namespace DGtal {
DGtal::IOException dgtalio;

std::ofstream out;
typename I::Domain domain = aImage.domain();
typename I::Domain domain = aImage.domain();
const typename I::Domain::Point &upBound = domain.upperBound();
const typename I::Domain::Point &lowBound = domain.lowerBound();
typename I::Domain::Point p = I::Domain::Point::diagonal(1);
typename I::Domain::Vector size = (domain.upperBound() - domain.lowerBound()) + p;
typename I::Domain::Vector size = (upBound - lowBound) + p;
typename I::Domain::Vector center = lowBound + ((upBound - lowBound)/2);
typename I::Value val;

try
{
out.open(filename.c_str());

//Longvol format
out << "Center-X: " << center[0] <<std::endl;
out << "Center-Y: " << center[1] <<std::endl;
out << "Center-Z: " << center[2] <<std::endl;
out << "X: "<< size[0]<<std::endl;
out << "Y: "<< size[1]<<std::endl;
out << "Z: "<< size[2]<<std::endl;
Expand Down
16 changes: 9 additions & 7 deletions src/DGtal/io/writers/VolWriter.ih
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,23 @@ namespace DGtal {
DGtal::IOException dgtalio;

std::ofstream out;
typename I::Domain::Vector size;
const typename I::Domain::Point &upBound = aImage.domain().upperBound();
const typename I::Domain::Point &lowBound = aImage.domain().lowerBound();
size[0]=upBound[0]-lowBound[0]+1;
size[1]=upBound[1]-lowBound[1]+1;
size[2]=upBound[2]-lowBound[2]+1;

typename I::Domain domain = aImage.domain();
const typename I::Domain::Point &upBound = domain.upperBound();
const typename I::Domain::Point &lowBound = domain.lowerBound();
typename I::Domain::Point p = I::Domain::Point::diagonal(1);
typename I::Domain::Vector size = (upBound - lowBound) + p;
typename I::Domain::Vector center = lowBound + ((upBound - lowBound)/2);

typename I::Value val;

try
{
out.open(filename.c_str());

//Vol format
out << "Center-X: " << center[0] <<std::endl;
out << "Center-Y: " << center[1] <<std::endl;
out << "Center-Z: " << center[2] <<std::endl;
out << "X: "<< size[0]<<std::endl;
out << "Y: "<< size[1]<<std::endl;
out << "Z: "<< size[2]<<std::endl;
Expand Down
8 changes: 4 additions & 4 deletions tests/images/testSliceImageFromFunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ bool testSliceImageFromFunctor()
projX(image.domain().upperBound()));


DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctor(20); aSliceFunctor.initAddOneDim(0);
DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctor(0); aSliceFunctor.initAddOneDim(0);
MySliceImageAdapter sliceImageX(image, domainX, aSliceFunctor, DGtal::functors::Identity());
res &= PGMWriter<MySliceImageAdapter>::exportPGM("exportedSlice2DDimX.pgm",sliceImageX);

DGtal::functors::Projector<DGtal::Z2i::Space> projY(0); projY.initRemoveOneDim(1);
DGtal::Z2i::Domain domainY(projY(image.domain().lowerBound()),
projY(image.domain().upperBound()));

DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctor2(20); aSliceFunctor2.initAddOneDim(1);
DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctor2(0); aSliceFunctor2.initAddOneDim(1);
MySliceImageAdapter sliceImageY(image, domainY, aSliceFunctor2, DGtal::functors::Identity());
res &= PGMWriter<MySliceImageAdapter>::exportPGM("exportedSlice2DDimY.pgm",sliceImageY);

Expand All @@ -92,13 +92,13 @@ bool testSliceImageFromFunctor()
projZ(image.domain().upperBound()));


DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctor3(20); aSliceFunctor3.initAddOneDim(2);
DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctor3(0); aSliceFunctor3.initAddOneDim(2);
MySliceImageAdapter sliceImageZ(image, domainZ, aSliceFunctor3, DGtal::functors::Identity());
res &= PGMWriter<MySliceImageAdapter>::exportPGM("exportedSlice2DDimZ.pgm",sliceImageZ);


PointVector<3, int> center(0,0,0);
DGtal::functors::SliceRotator2D< HyperRectDomain<SpaceND<3, int> >, int> sliceRot(2, image.domain(), 20, 2, 0.5, center);
DGtal::functors::SliceRotator2D< HyperRectDomain<SpaceND<3, int> >, int> sliceRot(2, image.domain(), 0, 2, M_PI/4.0, center);


MyRotatorSliceImageAdapter sliceRotImageZ(image, domainZ, sliceRot, DGtal::functors::Identity());
Expand Down
41 changes: 39 additions & 2 deletions tests/io/readers/testVolReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool testVolReader()

bool testIOException()
{
unsigned int nbok = 0;
unsigned int nbok = 0;
unsigned int nb = 0;

trace.beginBlock ( "Testing VolReader ..." );
Expand Down Expand Up @@ -136,21 +136,58 @@ bool testIOException()
return nbok == nb;
}

bool testConsistence()
{
trace.beginBlock ( "Testing VolWriter ..." );

typedef SpaceND<3> Space4Type;
typedef HyperRectDomain<Space4Type> TDomain;
typedef TDomain::Point Point;

//Default image selector = STLVector
typedef ImageSelector<TDomain, unsigned char>::Type Image;
TDomain domain(Point(-17,-14,-13), Point(5,7,11));
Image image(domain);
trace.info() << image.domain() <<endl;

VolWriter<Image>::exportVol("testConsistence.vol",image);

trace.endBlock();

trace.beginBlock ( "Testing VolReader ..." );

Image image2 = VolReader<Image>::importVol( "testConsistence.vol" );

trace.info() << image2.domain() <<endl;
trace.endBlock();

if( image.domain().lowerBound() != image2.domain().lowerBound()
|| image.domain().upperBound() != image2.domain().upperBound() )
{
return false;
}
return true;
}

///////////////////////////////////////////////////////////////////////////////
// Standard services - public :

int main( int argc, char** argv )
{
int aaaaa = 21/2;
std::cout << aaaaa << std::endl;

trace.beginBlock ( "Testing class VolReader" );
trace.info() << "Args:";
for ( int i = 0; i < argc; ++i )
trace.info() << " " << argv[ i ];
trace.info() << endl;

bool res = testVolReader() && testIOException(); // && ... other tests
bool res = testVolReader() && testIOException() && testConsistence(); // && ... other tests
trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
trace.endBlock();
return res ? 0 : 1;

}
// //
///////////////////////////////////////////////////////////////////////////////