Add support for loading 3D images using the "XT" format (an old Inrimage

format, 1994).
This commit is contained in:
Laurent Rineau 2008-07-30 12:10:59 +00:00
parent 766ebc992e
commit 1468c26496
4 changed files with 271 additions and 7 deletions

View File

@ -1,3 +1,5 @@
cmake_minimum_required(VERSION 2.4.5)
set ( prj Surface_mesher_Qt4_Demo )
project ( ${prj} )
@ -9,12 +11,12 @@ set(PACKAGE_ROOT ../../../)
# Add several CGAL packages to the include and link paths,
# if they lie in ${PACKAGE_ROOT}/.
foreach(INC_DIR ${PACKAGE_ROOT}/include ${PACKAGE_ROOT}/../Mesh_2/include ${PACKAGE_ROOT}/../Data_structure_for_queries_3/include ${PACKAGE_ROOT}/../Marching_cube/include ${PACKAGE_ROOT}/../CGALimageIO/include)
foreach(INC_DIR ${PACKAGE_ROOT}/include ${PACKAGE_ROOT}/../Mesh_2/include ${PACKAGE_ROOT}/../Data_structure_for_queries_3/include ${PACKAGE_ROOT}/../Marching_cube/include ${PACKAGE_ROOT}/../CGALimageIO/include ${PACKAGE_ROOT}/../GraphicsView/include)
if (EXISTS ${INC_DIR})
include_directories (BEFORE ${INC_DIR})
endif()
endforeach()
foreach(LIB_DIR ${PACKAGE_ROOT}/../CGALimageIO/src/CGALimageIO)
foreach(LIB_DIR ${PACKAGE_ROOT}/../CGALimageIO/src/CGALimageIO ${PACKAGE_ROOT}/../GraphicsView/src/CGALQt4)
if (EXISTS ${LIB_DIR})
link_directories (${LIB_DIR})
endif()
@ -46,7 +48,7 @@ if ( CGAL_FOUND )
include_directories(${bimap_DIR})
add_definitions(-DCGAL_USE_BOOST_BIMAP)
endif()
endif(EXISTS ${bimap_DIR}/bimap.hpp)
endif(EXISTS ${bimap_DIR}/boost/bimap/bimap.hpp)
if( VTK_FOUND )
# if( ${VTK_MAJOR_VERSION} STRGREATER "5")
@ -97,7 +99,7 @@ if ( CGAL_FOUND )
target_link_libraries( ${prj} CGAL CGAL-ImageIO ${CGAL_3RD_PARTY_LIBRARIES})
endif()
target_link_libraries( ${prj} ${QT_LIBRARIES} ${QGLVIEWER_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${PRJ_VTK_LIBS})
target_link_libraries( ${prj} CGAL-Qt4 ${QT_LIBRARIES} ${QGLVIEWER_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${PRJ_VTK_LIBS})
endif()
endif(CGAL_FOUND)

View File

@ -0,0 +1,187 @@
/*********************************************************************
* 25 - 02 - 97
* gestion des fichiers image ELF
*
*********************************************************************/
#ifndef CGAL_FILE_XT_H
#define CGAL_FILE_XT_H
#include <stdio.h>
#include <string.h>
#include <CGAL/config.h>
namespace CGAL {
namespace Total {
void permuteLong(char *a)
{
char tmp;
#ifdef CGAL_LITTLE_ENDIAN
tmp=a[0]; a[0]=a[3]; a[3]=tmp;
tmp=a[1]; a[1]=a[2]; a[2]=tmp;
#endif
}
void permuteLongTab(long *a,int nb)
{
int i;
#ifdef CGAL_LITTLE_ENDIAN
for(i=0;i<nb;i++) permuteLong( (char *) &a[i]);
#endif
}
void permuteShort(char *a)
{
char tmp;
#ifdef CGAL_LITTLE_ENDIAN
tmp=a[0]; a[0]=a[1]; a[1]=tmp;
#endif
}
void permuteShortTab(short *a, int nb)
{
int i;
#ifdef CGAL_LITTLE_ENDIAN
for(i=0;i<nb;i++) permuteShort( (char *) &a[i]);
#endif
}
void permuteFloat(char *a )
{
char tmp;
#ifdef CGAL_LITTLE_ENDIAN
tmp=a[0]; a[0]=a[3]; a[3]=tmp;
tmp=a[1]; a[1]=a[2]; a[2]=tmp;
#endif
}
void permuteFloatTab(float *a, int nb)
{
int i;
#ifdef CGAL_LITTLE_ENDIAN
for(i=0;i<nb;i++) permuteFloat((char *) &a[i]);
#endif
}
void permuteDouble(char *a )
{
char tmp;
#ifdef CGAL_LITTLE_ENDIAN
tmp=a[0]; a[0]=a[3]; a[3]=tmp;
tmp=a[1]; a[1]=a[2]; a[2]=tmp;
#endif
}
void permuteDoubleTab(double *a, int nb)
{
int i;
#ifdef CGAL_LITTLE_ENDIAN
for(i=0;i<nb;i++) permuteDouble((char *) &a[i]);
#endif
}
/*******************************************************************/
int lire_longueur_trace(const char * nomfich, long * long_trace)
{
FILE *fin;
int flag=0;
if ( (fin=fopen(nomfich,"rw"))!=NULL )
{
fseek(fin,4,0);
fread(long_trace,4,1,fin);
permuteLong((char *)long_trace);
fclose(fin);
}
else flag=-1;
return(flag);
}
/********************************************************************/
int lire_nb_trace(const char * nomfich, long * nb_trace)
{
FILE *fin;
int flag=0;
if ( (fin=fopen(nomfich,"rw"))!=NULL )
{
fseek(fin,8,0);
fread(nb_trace,4,1,fin);
permuteLong((char *)nb_trace);
fclose(fin);
}
else flag=-1;
return(flag);
}
/********************************************************************/
int lire_nb_plan(const char * nomfich, long * nb_plan)
{
FILE *fin;
int flag=0;
if ( (fin=fopen(nomfich,"rw"))!=NULL )
{
fseek(fin,12,0);
fread(nb_plan,4,1,fin);
permuteLong((char *)nb_plan);
fclose(fin);
}
else flag=-1;
return(flag);
}
/********************************************************************/
int lire_nb_octet(const char * nomfich, long * nb_octet)
{
FILE *fin;
int flag=0;
if ( (fin=fopen(nomfich,"rw"))!=NULL )
{
fseek(fin,36,0);
fread(nb_octet,4,1,fin);
permuteLong((char *)nb_octet);
fclose(fin);
}
else flag=-1;
return(flag);
}
/********************************************************************/
int lire_longueur_entete(const char * nomfich, long * long_entete)
{
FILE *fin;
int flag=0;
if ( (fin=fopen(nomfich,"rw"))!=NULL )
{
fseek(fin,72,0);
fread(long_entete,4,1,fin);
permuteLong((char *)long_entete);
fclose(fin);
}
else flag=-1;
return(flag);
}
} // end namespace Total
} // end namespace CGAL
#endif // CGAL_FILE_XT_H

View File

@ -11,6 +11,8 @@
#include "mainwindow.h"
#include "isovalues_list.h"
#include "File_XT.h" // format XT from Total/ELF
#include <QApplication>
#include <QFileDialog>
#include <QAction>
@ -25,6 +27,8 @@
#include <GL/glu.h>
#include <CGAL/Surface_mesher/Standard_criteria.h>
// #include <CGAL/Surface_mesher/Image_surface_oracle_3.h>
#include <CGAL/Surface_mesher/Implicit_surface_oracle_3.h>
#include <CGAL/Surface_mesher/Vertices_on_the_same_psc_element_criterion.h>
#include <CGAL/IO/Complex_2_in_triangulation_3_file_writer.h>
@ -155,7 +159,7 @@ Volume::Volume(MainWindow* mw) :
m_sm_angle(30),
m_sm_radius(0),
m_sm_distance(0),
m_relative_precision(0.000001),
m_relative_precision(0.0000001),
m_view_surface(false),
m_view_mc(false),
m_triangulation_color(QColor(Qt::green)),
@ -349,6 +353,73 @@ void Volume::open_vtk(const QString& filename)
}
}
// Total 3D images (XT format, that is the old Inrimage format, 1994.
bool Volume::open_xt(const QString& filename)
{
mw->show_only("volume");
fileinfo.setFile(filename);
if(fileinfo.isDir())
{
return false;
}
if(!fileinfo.isReadable())
{
QMessageBox::warning(mw, mw->windowTitle(),
tr("Cannot read file <tt>%1</tt>!").arg(filename));
status_message(tr("Opening of file %1 failed!").arg(filename));
return false;
}
else
{
long dimx, dimy, dimz;
long word_dim;
long header_size;
const char* filename_stl = qPrintable(filename);
CGAL::Total::lire_longueur_entete(filename_stl, &header_size);
CGAL::Total::lire_nb_octet(filename_stl, &word_dim);
CGAL::Total::lire_longueur_trace(filename_stl, &dimx);
CGAL::Total::lire_nb_trace(filename_stl, &dimy);
CGAL::Total::lire_nb_plan(filename_stl, &dimz);
vtkImageReader* vtk_reader = vtkImageReader::New();
vtk_reader->SetFileName(filename_stl);
switch(word_dim) {
case 8:
vtk_reader->SetDataScalarTypeToUnsignedChar();
break;
case 16:
vtk_reader->SetDataScalarTypeToUnsignedShort();
break;
default:
return false;
}
vtk_reader->SetHeaderSize(header_size);
vtk_reader->SetDataExtent(1, dimx, 1, dimy, 1, dimz);
vtk_reader->SetDataSpacing(1., 1., 1.);
vtk_reader->SetFileDimensionality(3);
vtk_reader->Update();
vtk_reader->Print(std::cerr);
vtkImageData* vtk_image = vtk_reader->GetOutput();
vtk_image->Print(std::cerr);
if(!m_image.read_vtk_image_data(vtk_image))
{
QMessageBox::warning(mw, mw->windowTitle(),
tr("Error with file <tt>%1</tt>:\nunknown file format!").arg(filename));
status_message(tr("Opening of file %1 failed!").arg(filename));
return false;
}
else
{
status_message(tr("File %1 successfully opened.").arg(filename));
finish_open();
}
return true;
}
}
#else // CGAL_USE_VTK
void Volume::opendir(const QString&) {}
#endif // CGAL_USE_VTK
@ -373,7 +444,7 @@ void Volume::open(const QString& filename)
}
else
{
if(!m_image.read(filename.toStdString().c_str()))
if(!m_image.read(filename.toStdString().c_str()) && !open_xt(filename))
{
QMessageBox::warning(mw, mw->windowTitle(),
@ -605,6 +676,7 @@ void Volume::display_surface_mesher_result()
// surface mesh traits class
typedef CGAL::Surface_mesher::Implicit_surface_oracle_3<Kernel,
// typedef CGAL::Surface_mesher::Image_surface_oracle_3<Kernel,
Surface_3,
Classify_from_isovalue_list,
Generate_surface_identifiers> Oracle;
@ -655,7 +727,9 @@ void Volume::display_surface_mesher_result()
<< ", distance=" << m_sm_distance << "\n";
// meshing surface
make_surface_mesh(c2t3, surface, oracle, criteria, CGAL::Non_manifold_tag(), 0);
make_surface_mesh(c2t3, surface, oracle, criteria,
// CGAL::Non_manifold_tag(), 0);
CGAL::Manifold_tag(), 0);
sm_timer.stop();
not_busy();

View File

@ -149,6 +149,7 @@ public slots:
void open(const QString& filename);
#ifdef CGAL_USE_VTK
void open_vtk(const QString& filename);
bool open_xt(const QString& filename);
#endif
void opendir(const QString& dirname);
void finish_open();