Commit 951a7236 authored by Sylvain Thery's avatar Sylvain Thery

MAJ img3DIO texture et text3D,

modification apps_cmake
parent 74a258a0
cmake_minimum_required(VERSION 2.6)
project(geometryAssertD)
project(testing_debug)
SET(CMAKE_BUILD_TYPE Debug)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CGoGN_ROOT_DIR}/include
......@@ -12,11 +11,15 @@ include_directories(
)
# define libs path
link_directories(
${CGoGN_ROOT_DIR}/lib/Debug
${CGoGN_ROOT_DIR}/lib/Release
)
IF(WIN32)
link_directories(
${CGoGN_ROOT_DIR}/lib/$(ConfigurationName)
${CGoGN_ROOT_DIR}/lib/Release )
ELSE(WIN32)
link_directories(
${CGoGN_ROOT_DIR}/lib/Debug
${CGoGN_ROOT_DIR}/lib/Release )
ENDIF(WIN32)
#define exec to compile
......
Principe des applications dans CGoGN_Apps
Faire un repertoire CGoGN_Apps ou on veut. Y mettre des sous répertoires
contenant chacun une application/
Le CMakeLists.txt a la racine de l'application doit commencer par
cmake_minimum_required(VERSION 2.8)
PROJECT(NOM_DE_L_APPLICATION)
SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/../../CGoGN)
INCLUDE(${CGoGN_ROOT_DIR}/build/apps_cmake.txt)
Le ../../CGoGN correspond au chemin relatif vers votre version de CGoGN
(ici placée au même niveau que CGoGN_Apps)
Si vous voulez faire des sous répertoires release et debug:
add_subdirectory(${CMAKE_SOURCE_DIR}/Release Release)
IF (NOT WIN32)
add_subdirectory(${CMAKE_SOURCE_DIR}/Debug Debug)
ENDIF (NOT WIN32)
Le CMakeLists (Release par exemple) doit ensuite contenir
SET(CMAKE_BUILD_TYPE Release)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release/)
include_directories(
${CGoGN_ROOT_DIR}/include # for CGoGN
${COMMON_INCLUDES} # for thirdparty & system
${CMAKE_CURRENT_SOURCE_DIR} # for application
${CMAKE_CURRENT_BINARY_DIR} # for qt (ui,moc,etc.) if necessary
)
add_executable( mon_exec ${CMAKE_SOURCE_DIR}/mon_source.cpp)
target_link_libraries( mon_exec ${CGoGN_LIBS_R} ${COMMON_LIBS})
Pour le compiler le plus propre est de faire un repertoire build,
d'aller à l'interieur et de faire ccmake .. (j'ai bien ecrit "..")
ccmake (ou un equivalent type cmake-gui) permet de mettre à jour les variables,
ici WITH_QT, WITH_ASSIMP, WITH_NUMERICAL, WITH_ZINRI.
Ceci ajoutera automatiquement tout ce qu'il faut aux variables COMMON_INCLUDES
et COMMON_LIBS.
On peut aussi utiliser cmake avec l'option -D (moins pratique).
# A mettre juste apres la definition de CGoGN_ROOT_DIR a la racine du CGoGN_Apps
# include(${CGoGN_ROOT_DIR}/build/apps_cmake.txt)
SET(CMAKE_MODULE_PATH " ${CMAKE_MODULE_PATH} ${CGoGN_ROOT_DIR}/cmake_modules/")
SET(CMAKE_MODULE_PATH ${CGoGN_ROOT_DIR}/cmake_modules/)
SET ( WITH_ASSIMP ON CACHE BOOL "need Assimp")
......@@ -30,7 +30,7 @@ ENDIF (DEFINED ASSERTON)
add_definitions(-DSHADERPATH="${CGoGN_ROOT_DIR}/lib/Shaders/")
# define includes of external libs
SET(CGoGN_EXT_INCLUDES
SET(COMMON_INCLUDES
${CGoGN_ROOT_DIR}/ThirdParty/glm
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS}
......@@ -50,13 +50,13 @@ SET (COMMON_LIBS
#optionnal libs
IF (WITH_ASSIMP)
add_definitions(-DWITH_ASSIMP)
SET (CGoGN_EXT_INCLUDES ${CGoGN_EXT_INCLUDES} ThirdParty/Assimp/include)
SET (COMMON_INCLUDES ${COMMON_INCLUDES} ThirdParty/Assimp/include)
SET (COMMON_LIBS ${COMMON_LIBS} assimp)
ENDIF (WITH_ASSIMP)
IF (WITH_ZINRI)
add_definitions(-DWITH_ZINRI)
SET (CGoGN_EXT_INCLUDES ${CGoGN_EXT_INCLUDES} ${CGoGN_ROOT_DIR}/ThirdParty/Zinri)
SET (COMMON_INCLUDES ${COMMON_INCLUDES} ${CGoGN_ROOT_DIR}/ThirdParty/Zinri)
SET (COMMON_LIBS ${COMMON_LIBS} Zinri)
ENDIF (WITH_ZINRI)
......@@ -66,16 +66,20 @@ IF (WITH_QT)
SET(QT_USE_QTOPENGL TRUE)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
SET (CGoGN_EXT_INCLUDES ${CGoGN_EXT_INCLUDES} ${QT_INCLUDE_DIR})
SET (CGoGN_EXT_LIBS ${CGoGN_EXT_LIBS} ${QT_LIBRARIES})
SET (COMMON_INCLUDES ${COMMON_INCLUDES} ${QT_INCLUDE_DIR})
SET (COMMON_LIBS ${COMMON_LIBS} ${QT_LIBRARIES})
ENDIF (WITH_QT)
IF (WITH_NUMERICAL)
add_definitions(-DWITH_NUMERICAL)
SET (NUMERICAL_INCLUDES ${CGoGN_ROOT_DIR}/ThirdParty/Numerical ${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig)
SET (NUMERICAL_LIBS f2c blas numerical lapack)
# SET (NUMERICAL_INCLUDES ${CGoGN_ROOT_DIR}/ThirdParty/Numerical ${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig)
# SET (NUMERICAL_LIBS f2c blas numerical lapack)
SET (COMMON_INCLUDES ${COMMON_INCLUDES} ${CGoGN_ROOT_DIR}/ThirdParty/Numerical ${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig)
SET (COMMON_LIBS ${COMMON_LIBS} f2c blas numerical lapack)
ENDIF (WITH_NUMERICAL)
# qq definition specifiques pour mac
IF(APPLE)
# attention a changer pour chercher la bonne version automatiquement
......@@ -85,20 +89,15 @@ IF(APPLE)
SET(CMAKE_OSX_ARCHITECTURES x86_64)
ENDIF(APPLE)
# qq definition specifiques pour windows
IF(WIN32)
add_subdirectory(Release)
add_subdirectory(${CGoGN_ROOT_DIR}/Apps Apps)
set(CMAKE_PREFIX_PATH ${CGoGN_ROOT_DIR}/windows_dependencies CACHE STRING "path to dependencies")
set(CMAKE_CONFIGURATION_TYPES Release Debug)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Only Release or Debug" FORCE)
ELSE(WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
add_subdirectory(Release)
add_subdirectory(Debug)
add_subdirectory(${CGoGN_ROOT_DIR}/Apps Apps)
ENDIF(WIN32)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
SET(CGoGN_LIBS_D topologyD algoD containerD utilsD)
......
......@@ -180,7 +180,6 @@ void Image<DataType>::loadVox(char *filename)
template< typename DataType >
bool Image<DataType>::loadPNG3D(const char* filename)
{
CGoGN::Utils::Img3D_IO::initIO();
int tag;
//en fonction de DataType utiliser la bonne fonction de chargement,
......
......@@ -32,7 +32,7 @@ namespace CGoGN
namespace Utils
{
#ifdef WITH_QT
namespace Img3D_IO
{
/**
......@@ -40,13 +40,7 @@ namespace Img3D_IO
*/
enum TYPEIMG {BOOL8=1, VAL8, RGB8, VAL16, VALFLOAT};
#ifdef PORTED_TO_QIMAGE
/**
* Initialization of IO
* Necessary before any other call
*/
void initIO();
/**
* Load bool image (0/255)
......@@ -113,7 +107,7 @@ namespace Img3D_IO
/**
* Load 16 bits value image
* Load RGB 8 bits image
* Warning: the allocated data image contain w supplemntary bytes which store information
* @param filename evident
* @param w width of image (reference out)
......@@ -125,11 +119,11 @@ namespace Img3D_IO
* @param tag image tag (reference out)
* @return a pointer on the image data (that have been allocated by function)
*/
// unsigned short* loadVal_16(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& tag);
unsigned char* loadRGB(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& id);
/**
* Save 16bits val image
* Warning: the saved image contain w supplemntary bytes which store informations
* Save RGB 8 bits image
* Warning: the saved image contain 3w supplemntary bytes which store informations
* Warning: origin of image is lower left
* @param filename evident
* @param data a pointer on the image data
......@@ -141,10 +135,9 @@ namespace Img3D_IO
* @param vz voxel size z
* @param tag image tag
*/
// void saveVal_16(const std::string& filename, unsigned short* data, int w, int h, int d, float vx, float vy, float vz, int tag);
void saveRGB(const std::string& filename, unsigned char* data, int w, int h, int d, float vx, float vy, float vz, int tag);
/**
* Load float value image
* Load 16 bits value image
* Warning: the allocated data image contain w supplemntary bytes which store information
* @param filename evident
* @param w width of image (reference out)
......@@ -156,10 +149,10 @@ namespace Img3D_IO
* @param tag image tag (reference out)
* @return a pointer on the image data (that have been allocated by function)
*/
// float* loadVal_float(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& id);
// unsigned short* loadVal_16(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& tag);
/**
* Save float val image
* Save 16bits val image
* Warning: the saved image contain w supplemntary bytes which store informations
* Warning: origin of image is lower left
* @param filename evident
......@@ -172,11 +165,10 @@ namespace Img3D_IO
* @param vz voxel size z
* @param tag image tag
*/
// void saveVal_float(const std::string& filename, float* data, int w, int h, int d, float vx, float vy, float vz, int tag);
// void saveVal_16(const std::string& filename, unsigned short* data, int w, int h, int d, float vx, float vy, float vz, int tag);
/**
* Load RGB 8 bits image
* Load float value image
* Warning: the allocated data image contain w supplemntary bytes which store information
* @param filename evident
* @param w width of image (reference out)
......@@ -188,11 +180,11 @@ namespace Img3D_IO
* @param tag image tag (reference out)
* @return a pointer on the image data (that have been allocated by function)
*/
unsigned char* loadRGB(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& id);
// float* loadVal_float(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& id);
/**
* Save RGB 8 bits image
* Warning: the saved image contain 3w supplemntary bytes which store informations
* Save float val image
* Warning: the saved image contain w supplemntary bytes which store informations
* Warning: origin of image is lower left
* @param filename evident
* @param data a pointer on the image data
......@@ -204,10 +196,13 @@ namespace Img3D_IO
* @param vz voxel size z
* @param tag image tag
*/
void saveRGB(const std::string& filename, unsigned char* data, int w, int h, int d, float vx, float vy, float vz, int tag);
#endif
// void saveVal_float(const std::string& filename, float* data, int w, int h, int d, float vx, float vy, float vz, int tag);
} //namespace
#endif
} //namespace
} //namespace
......
......@@ -197,13 +197,10 @@ public:
typedef Geom::Vector<DIM,unsigned int> COORD;
protected:
/// id of image for DevIL
QImage* m_qimg;
template <typename TYPEDOUBLE>
TYPE applyFilterOneTexel(const Filter<DIM>& filter, const COORD& t) const;
/// swap two texel in dim 1 image
void swapTexels(unsigned int x0, unsigned int x1);
......@@ -225,21 +222,24 @@ public:
/// destructor
~Image();
/**
* swap two images
*/
virtual void swap(Image<DIM,TYPE>& img);
/**
* Load from memory ptr,
* a copy if performed (ptr could be destructed just after calling
* @param ptr a pointer on memory source image (allocation must be coherent with other parameters)
* @param w width of image
* @param h heighy of image
* @param bpp byte per pixel of image
*/
bool load(const unsigned char *ptr, unsigned int w, unsigned int h, unsigned int bpp)
#ifdef WITH_QT
/// load from file
bool load(const std::string& filename);
/// load from file with conversion (template type is type pixel image-
template <typename TYPE2 >
bool load(const std::string& filename, void (*convertFunc)(const TYPE2&, const TYPE&));
/// load from file
void save(const std::string& filename);
#endif
/**
* crop image
......
......@@ -256,15 +256,13 @@ void ImageData<DIM,TYPE>::convert(ImageData<DIM,TYPE2>& output, TYPE2 (*convertF
// implementation class Image
template < unsigned int DIM, typename TYPE >
Image<DIM,TYPE>::Image():
m_qimg(NULL)
Image<DIM,TYPE>::Image()
{
}
template < unsigned int DIM, typename TYPE >
Image<DIM,TYPE>::Image(const COORD& size):
ImageData<DIM,TYPE>(size),
m_qimg(NULL)
ImageData<DIM,TYPE>(size)
{
}
......@@ -272,12 +270,11 @@ m_qimg(NULL)
template < unsigned int DIM, typename TYPE >
Image<DIM,TYPE>::~Image()
{
if (this->m_qimg != NULL)
delete this->m_qimg;
m_qimg = NULL;
delete[] m_data_ptr;
this->m_data_ptr = NULL;
}
/*
template < unsigned int DIM, typename TYPE >
void Image<DIM,TYPE>::swap(Image<DIM,TYPE>& img)
{
......@@ -290,69 +287,41 @@ void Image<DIM,TYPE>::swap(Image<DIM,TYPE>& img)
ImageData<DIM,TYPE>::swap(img);
}
*/
template < unsigned int DIM, typename TYPE >
bool Image<DIM,TYPE>::load(const std::string& filename)
bool Image<DIM,TYPE>::load(const unsigned char *ptr, unsigned int w, unsigned int h, unsigned int bpp)
{
CGoGN_STATIC_ASSERT(DIM==2, incompatible_Vector_constructor_dimension);
QImage* ptr = new QImage(filename.c_str());
if (ptr == NULL)
{
delete ptr;
return false;
}
// get the info of images
unsigned int bpp = ptr->depth() / 8;
// compatible TYPE
if (bpp < sizeof(TYPE))
if (bpp != sizeof(TYPE))
{
CGoGNout << "Image::load incompatible type: bbp="<<bpp<< CGoGNendl;
CGoGNout << "Image::load incompatible type: bbp=" << bpp << CGoGNendl;
CGoGNout << "sizeof(TYPE)="<<sizeof(TYPE)<< CGoGNendl;
delete ptr;
return false;
}
// destroy old data
if (this->m_qimg != NULL)
delete this->m_qimg;
else if (this->m_data_ptr != NULL)
if (this->m_data_ptr != NULL)
delete[] this->m_data_ptr;
if (bpp > sizeof(TYPE))
{
if (sizeof(TYPE) == 3)
{
QImage img = ptr->convertToFormat(QImage::Format_RGB888);
this->m_qimg = new QImage(img);
}
else if (sizeof(TYPE) == 1)
{
QImage img = ptr->convertToFormat(QImage::Format_Indexed8);
this->m_qimg = new QImage(img);
}
delete ptr;
}
else
this->m_qimg = ptr;
this->m_size[0] = this->m_qimg->width();
this->m_size[1] = m_qimg->height();
this->m_data_ptr = new T[sizeof(TYPE)*w*h];
memcpy(this->m_data_ptr, img.bits(), sizeof(TYPE)*w*h);
this->m_size[0] = w;
this->m_size[1] = h;
this->m_data_ptr = reinterpret_cast<TYPE*>(m_qimg->bits());
this->computeSub();
return true;
}
#ifdef WITH_QT
template < unsigned int DIM, typename TYPE >
template <typename TYPE2 >
bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(const TYPE2&, const TYPE&))
bool Image<DIM,TYPE>::load(const std::string& filename)
{
CGoGN_STATIC_ASSERT(DIM==2, incompatible_Vector_constructor_dimension);
......@@ -360,7 +329,7 @@ bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(cons
if (ptr == NULL)
{
delete ptr;
CGoGNout << "Impossible to load "<< filename << std::endl;
return false;
}
......@@ -368,18 +337,16 @@ bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(cons
unsigned int bpp = ptr->depth() / 8;
// compatible TYPE
if (bpp != sizeof(TYPE))
if (bpp < sizeof(TYPE))
{
CGoGNout << "Image::load incompatible type: bbp="<<bpp<< CGoGNendl;
CGoGNout << "Image::load incompatible type: bbp=" << bpp << CGoGNendl;
CGoGNout << "sizeof(TYPE)="<<sizeof(TYPE)<< CGoGNendl;
delete ptr;
return false;
}
// destroy old data
if (this->m_qimg != NULL)
delete this->m_qimg;
else if (this->m_data_ptr != NULL)
if (this->m_data_ptr != NULL)
delete[] this->m_data_ptr;
if (bpp > sizeof(TYPE))
......@@ -387,34 +354,27 @@ bool Image<DIM,TYPE>::load(const std::string& filename, void (*convertFunc)(cons
if (sizeof(TYPE) == 3)
{
QImage img = ptr->convertToFormat(QImage::Format_RGB888);
this->m_qimg = new QImage(img);
this->m_data_ptr = new T[3*img.width()*img.height()];
memcpy(this->m_data_ptr, img.bits(), 3*img.width()*img.height());
}
else if (sizeof(TYPE) == 1)
{
QImage img = ptr->convertToFormat(QImage::Format_Indexed8);
this->m_qimg = new QImage(img);
this->m_data_ptr = new T[img.width()*img.height()];
memcpy(this->m_data_ptr, img.bits(), img.width()*img.height());
}
delete ptr;
}
else
this->m_qimg = ptr;
this->m_size[0] = this->m_qimg->width();
this->m_size[1] = m_qimg->height();
}
else
{
this->m_data_ptr = new T[ptr->width()*ptr->height()];
memcpy(this->m_data_ptr, ptr->bits(), ptr->width()*ptr->height());
}
this->m_size[0] = ptr->width();
this->m_size[1] = ptr->height();
this->computeSub();
this->m_data_ptr = new TYPE[this->m_sizeSub[1]];
TYPE2 *ptrSrc = reinterpret_cast<TYPE2*>(ptr->bits());
TYPE* ptrDst = this->m_data_ptr;
for (unsigned int i = 0; i < this->m_sizeSub[1]; ++i)
(*convertFunc)(*ptrSrc++, *ptrDst++);
delete this->m_qimg;
this->m_qimg=NULL;
delete ptr;
return true;
}
......@@ -424,24 +384,7 @@ void Image<DIM,TYPE>::save(const std::string& filename)
{
CGoGN_STATIC_ASSERT(DIM==2, incompatible_Vector_constructor_dimension);
if (this->m_qimg != NULL)
{
switch(sizeof(TYPE))
{
case 1:
this->m_qimg->save(QString(filename), QImage::Format_Indexed8);
break;
case 3:
this->m_qimg->save(QString(filename), QImage::Format_RGB888);
break;
case 4:
this->m_qimg->save(QString(filename), QImage::Format_ARGB32);
break;
default:
break;
}
}
else if (this->m_data_ptr != NULL)
if (this->m_data_ptr != NULL)
{
switch(sizeof(TYPE))
{
......@@ -468,7 +411,7 @@ void Image<DIM,TYPE>::save(const std::string& filename)
}
}
}
#endif
template < unsigned int DIM, typename TYPE >
......
......@@ -34,14 +34,9 @@ namespace CGoGN
namespace Utils
{
#ifdef WITH_QT
namespace Img3D_IO
{
#ifdef PORTED_TO_QIMAGE
void initIO()
{
ilInit();
iluInit();
}
template<typename DataType>
DataType* compressZ8(DataType* src, int w, int h, int d, int& new_d)
......@@ -169,34 +164,26 @@ void saveBool(const std::string& filename, unsigned char* data, int w, int h, in
unsigned char* loadVal_8(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& tag)
{
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
ilEnable(IL_ORIGIN_SET);
ILuint imgName;
ilGenImages(1,&imgName);
ilBindImage(imgName);
ilLoadImage(filename);
QImage* ptrImg = new QImage(filename.c_str());
if (ptrImg==NULL)
return NULL;
// get the info of 2D image
w = ilGetInteger(IL_IMAGE_WIDTH);
h = ilGetInteger(IL_IMAGE_HEIGHT);
ILuint bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
QImage img(filename, QImage::Format_Indexed8);
w = img->width();
h = img.height();
int bpp = img.depth();
w = ptrImg->width();
h = ptrImg->height();
unsigned int bpp = ptrImg->depth();
// image OK ?
if ((bpp!=8))
return NULL;
unsigned char* ptr=ilGetData();
unsigned char* ptr=bits();
int* ptr_int = reinterpret_cast<int*>(ptr+(w*(h-1)));
int t = *ptr_int++;
if ((t!= BOOL8) && (t!= VAL8))
return NULL;
tag = *ptr_int++;
w = *ptr_int++;
h = *ptr_int++;
......@@ -211,13 +198,15 @@ unsigned char* loadVal_8(const std::string& filename, int& w, int& h, int &d, fl
// uncompress data
unsigned char* data = uncompressZ8<unsigned char>(ptr,w,h,d);
// free il image
ilDeleteImages(1,&imgName);
delete prtImg;
// return 3D image
return data;
}
// t == VAL8
return ptr;
unsigned char* ptr2 = new unsigned char[w*h*d];
memcpy (ptr2, ptr, w*h*d);
delete prtImg;
return ptr2;
}
......@@ -225,32 +214,46 @@ unsigned char* loadVal_8(const std::string& filename, int& w, int& h, int &d, fl
void saveVal(const std::string& filename, unsigned char* data, int w, int h, int d, float vx, float vy, float vz, int tag)
{
// init image2D
QImage img(w,(h*d)+1,QImage::Format_Indexed8);
memcpy(img.bits(), data, w*h*d);
// add 3D info
int *entete1=reinterpret_cast<int*>(img.bits()+w*h*d); // get the end of 3D data
*entete1++ = VAL8;
*entete1++ = tag;
*entete1++ = w;
*entete1++ = h;
*entete1++ = d;
float *entete2=reinterpret_cast<float*>(entete1);
*entete2++ = vx;
*entete2++ = vy;
*entete2++ = vz;
// save image
img.save(filename.c_str(),QImage::Format_Indexed8);
}
unsigned char* loadRGB(const std::string& filename, int& w, int& h, int &d, float& vx, float& vy, float& vz, int& tag)
{
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
ilEnable(IL_ORIGIN_SET);
ILuint imgName;
ilGenImages(1,&imgName);
ilBindImage(imgName);
ilLoadImage(filename);
QImage* ptrImg = new QImage(filename.c_str());
if (ptrImg==NULL)
return NULL;
// get the info of 2D image
w = ilGetInteger(IL_IMAGE_WIDTH);
h = ilGetInteger(IL_IMAGE_HEIGHT);
ILuint bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
w = ptrImg->width();
h = ptrImg->height();
unsigned int bpp = ptrImg->depth();
// image OK ?
if ((bpp!=3))
if ((bpp!=24))
return NULL;
unsigned char* ptr=ilGetData();
unsigned char* ptr=bits();
int* ptr_int = reinterpret_cast<int*>(ptr+3*(w*(h-1)));
int t = *ptr_int++;
if (t!= RGB8)
......@@ -264,53 +267,23 @@ unsigned char* loadRGB(const std::string& filename, int& w, int& h, int &d, floa
vy = *ptr_float++;
vz = *ptr_float++;
return ptr;
// WARNING NO COPY: IL IMAGE HAS NOT BEEN FREED
// IMPORTANT ??? I DON'T THINK
unsigned char* ptr2 = new unsigned char[3*w*h*d];
memcpy (ptr2, ptr, 3*w*h*d);
delete prtImg;
return ptr2;
}
void saveVal(const std::string& filename, unsigned char* data, int w, int h, int d, float vx, float vy, float vz, int tag)
{
// init image2D
ILuint imgName;
ilGenImages(1,&imgName);
ilBindImage(imgName);
ilTexImage(w,(h*d)+1,1,1,IL_LUMINANCE,IL_UNSIGNED_BYTE,NULL);
// copy 3D image in 2D image
ilSetPixels(0,0,0,w,h*d,1,IL_LUMINANCE, IL_UNSIGNED_BYTE, data);
// add 3D info
int *entete1=reinterpret_cast<int*>(ilGetData()+w*h*d); // get the end of 3D data
*entete1++ = VAL8;
*entete1++ = tag;
*entete1++ = w;
*entete1++ = h;
*entete1++ = d;
float *entete2=reinterpret_cast<float*>(entete1);
*entete2++ = vx;
*entete2++ = vy;
*entete2++ = vz;
// save image
ilEnable(IL_FILE_OVERWRITE);
ilSaveImage(filename);
ilDeleteImages(1,&imgName);
}