40 #include "math-extension.hh"
53 int AFirstPlane,
int ANbPlaneToRead) :
60 FStream.open(AFilename.c_str(), std::ios::in);
62 if (!FStream.good() || !findPlaneSize())
68 FNbPlaneToRead = ANbPlaneToRead > 0 ? ANbPlaneToRead+AFirstPlane+1 : -1;
70 std::cout <<
" XMin: " << FXMin
72 <<
" XStep: " << FXStep
75 std::cout <<
" YMin: " << FYMin
77 <<
" YStep: " << FYStep
83 while (
FIsOk && AFirstPlane >= 0)
95 if (FStream.is_open())
100 bool CImage3dCEA::readVoxel(
int* Ax,
int* Ay,
int* Az, uint8_t* AColor)
102 FStreamPos = FStream.tellg();
103 FStream >> *Ax >> *Ay >> *Az >> *AColor;
104 return FStream.good();
108 void CImage3dCEA::unreadLastVoxel()
110 FStream.seekg(FStreamPos, std::ios::beg);
114 bool CImage3dCEA::findPlaneSize()
116 std::streampos memo = FStreamPos;
117 FStream.seekg(0, std::ios::beg);
124 if (! readVoxel(&x,&y,&z0,&c))
126 FStream.seekg(memo, std::ios::beg);
130 FXMin = FXMax = x; FXStep = 0;
131 FYMin = FYMax = y; FYStep = 0;
133 bool ok = readVoxel(&x,&y,&z,&c);
138 FXStep = pgcd(FXStep, labs(FXMin - x));
139 FYStep = pgcd(FYStep, labs(FYMin - y));
141 if (x < FXMin) FXMin = x;
142 if (x > FXMax) FXMax = x;
143 if (y < FYMin) FYMin = y;
144 if (y > FYMax) FYMax = y;
146 ok = readVoxel(&x,&y,&z,&c);
152 if (FXStep == 0) FXStep = 1;
153 if (FYStep == 0) FYStep = 1;
155 FWidth = (FXMax - FXMin) / FXStep + 1;
156 FHeight = (FYMax - FYMin) / FYStep + 1;
159 FStream.seekg(FStreamPos, std::ios::beg);
164 uint8_t** CImage3dCEA::allocArray()
166 uint8_t** result =
new uint8_t* [
FWidth];
168 for (
unsigned int i=0; i<
FWidth; ++i)
169 result[i] =
new uint8_t [
FHeight];
175 void CImage3dCEA::freeArray(uint8_t** AArray)
180 for (
unsigned int i=0; i<
FWidth; ++i)
189 FActuPlane = allocArray();
191 for (
unsigned int x=0; x<
FWidth; ++x)
192 for (
unsigned int y=0; y<
FHeight; ++y)
193 FActuPlane[x][y] = 0;
200 readVoxel(&x,&y,&Z,&c);
206 ok = readVoxel(&x,&y,&z,&c) && z==Z;
208 if (ok && FXMin <= x && x <= FXMax && FYMin <= y && y <= FYMax)
209 FActuPlane[(x-FXMin)/FXStep][(y-FYMin)/FYStep] = c;
220 unsigned int Ax2,
unsigned int Ay2,
bool Az2)
const
223 (Az1 ? FActuPlane : FPrevPlane)[Ax1][Ay1] ==
224 (Az2 ? FActuPlane : FPrevPlane)[Ax2][Ay2];
229 int ARed,
int,
int,
int )
const
231 return (Az ? FActuPlane : FPrevPlane)[Ax][Ay] == ARed;
239 uint8_t** & plane = AActuPlane ? FActuPlane : FPrevPlane;
250 FPrevPlane = FActuPlane;