Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
image-3d-magick.icc
Go to the documentation of this file.
1 /*
2  * lib-extraction-images : Extraction de cartes à partir d'images 2D et 3D.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-extraction-images
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include <cstring>
26 #include <cassert>
27 #include <iostream>
28 
29 namespace GMap3d
30 {
31 //******************************************************************************
32 INLINE
33 CImage3dMagick::CImage3dMagick(const std::string & AFilename, int FirstPlane,
34  int NbPlaneToRead, unsigned int Lg) :
35  CImage3d(FirstPlane),
36  FLg(Lg)
37 {
38  FPrevPlane = NULL;
39  FActuPlane = NULL;
40 
41  computePrefix(AFilename); // Initialise FPrefix et FPrefixLongueur
42 
43  if (NbPlaneToRead == 0)
44  if (FPrefix == AFilename) // Si le nom du fichier ne contient pas %
45  FNbPlaneToRead = 1; // Alors on lit un seul fichier.
46  else
47  FNbPlaneToRead = -1;
48  else
49  FNbPlaneToRead = NbPlaneToRead;
50 
51  FIsOk = readNextPlane();
52 }
53 //******************************************************************************
54 INLINE
56 {
57  delete FPrevPlane;
58  delete FActuPlane;
59 }
60 //******************************************************************************
61 INLINE
62 void CImage3dMagick::computePrefix(const std::string & AFileName)
63 {
64  assert(AFileName.length()!=0);
65 
66  FPrefix = AFileName;
67 
68  std::string::size_type pos = FPrefix.find("%");
69 
70  if (pos != std::string::npos)
71  {
72  char tmp[9+int(FLg/10)]; // Allocation possible grâce à la norme C99
73  sprintf(tmp,"%%0%dd",FLg);
74  FPrefix.replace(pos,1, tmp);
75  }
76 }
77 //******************************************************************************
78 INLINE
80 {
81  char * chaine = new char[FPrefix.length()+int(FLg/10)+1];
82  sprintf(chaine,FPrefix.c_str(),FActuPlaneIndex);
83  FActuPlane = new Magick::Image;
84 
85  try
86  {
87  FActuPlane->read(chaine); // Lecture du prochain plan
88  }
89  catch( Magick::Exception &error_ )
90  {
91  delete [] chaine;
92  return false;
93  }
94 
95  delete [] chaine;
96 
97  if (FPrevPlane == NULL)
98  {
99  FWidth = FActuPlane->columns();
100  FHeight = FActuPlane->rows ();
101  std::cout << "taille d'une plaque : "
102  << FWidth << "*" << FHeight << std::endl;
103  }
104 
105  assert(FActuPlane->columns() == FWidth );
106  assert(FActuPlane->rows () == FHeight);
107 
108  return true;
109 }
110 //******************************************************************************
111 INLINE
112 bool CImage3dMagick::sameVoxel(unsigned int Ax1, unsigned int Ay1, bool Az1,
113  unsigned int Ax2, unsigned int Ay2, bool Az2)
114  const
115 {
116  return
117  (Az1 ? FActuPlane : FPrevPlane)->pixelColor(Ax1,Ay1) ==
118  (Az2 ? FActuPlane : FPrevPlane)->pixelColor(Ax2,Ay2);
119 }
120 //******************************************************************************
121 INLINE
122 bool CImage3dMagick::sameVoxel(unsigned int Ax, unsigned int Ay, bool Az,
123  int ARed, int AGreen, int ABlue, int AAlpha)const
124 {
125  return (Az ? FActuPlane : FPrevPlane)->pixelColor(Ax,Ay) ==
126  Magick::Color(ARed, AGreen, ABlue, AAlpha);
127 }
128 //******************************************************************************
129 INLINE
130 void CImage3dMagick::freePlane(bool AActuPlane)
131 {
132  CImage3d::freePlane(AActuPlane);
133 
134  Magick::Image * & plane = AActuPlane ? FActuPlane : FPrevPlane;
135 
136  delete plane; // delete NULL ne fait rien mais ca marche
137  plane = NULL;
138 }
139 //******************************************************************************
140 INLINE
142 {
144 
145  FPrevPlane = FActuPlane;
146  FActuPlane = NULL;
147 }
148 //******************************************************************************
149 } // namespace GMap3d