fix whitespace and indentation

This commit is contained in:
ccolin 2022-01-09 17:04:57 +01:00
parent efec18499f
commit b9d5fd3aa7
1 changed files with 160 additions and 160 deletions

View File

@ -28,28 +28,28 @@ using namespace DGtal;
struct hueFct{ struct hueFct{
inline inline
unsigned int operator() (unsigned int aVal) const unsigned int operator() (unsigned int aVal) const
{ {
HueShadeColorMap<unsigned int> hueShade(0,255); HueShadeColorMap<unsigned int> hueShade(0,255);
Color col = hueShade((unsigned int)aVal); Color col = hueShade((unsigned int)aVal);
return (((unsigned int) col.red()) << 16)| (((unsigned int) col.green()) << 8)|((unsigned int) col.blue()); return (((unsigned int) col.red()) << 16)| (((unsigned int) col.green()) << 8)|((unsigned int) col.blue());
} }
}; };
// Définition du type de viewer à utiliser. // Définition du type de viewer à utiliser.
typedef Viewer3D<> ViewerType ; typedef Viewer3D<> ViewerType ;
// Définition du type de conteneur à utiliser pour l'image du premier exercice. // Définition du type de conteneur à utiliser pour l'image du premier exercice.
typedef ImageContainerBySTLVector<Z3i::Domain, float> Image3D; typedef ImageContainerBySTLVector<Z3i::Domain, float> Image3D;
// Définition du type de conteneur à utiliser pour l'image de la transformée en distance. // Définition du type de conteneur à utiliser pour l'image de la transformée en distance.
typedef ImageSelector<Z3i::Domain, unsigned char>::Type Image; typedef ImageSelector<Z3i::Domain, unsigned char>::Type Image;
// Parcours et traitement d'un volume. // Parcours et traitement d'un volume.
void imageSandbox(ViewerType& viewer, std::string filename); void imageSandbox(ViewerType& viewer, std::string filename);
// Tranformée en distance. // Tranformée en distance.
void transformeeEnDistance(ViewerType& viewer, std::string filename); void transformeeEnDistance(ViewerType& viewer, std::string filename);
// Méthode pour générer des voxels de manière aléatoire. // Méthode pour générer des voxels de manière aléatoire.
template<typename Image> template<typename Image>
void randomSeeds(Image &image, const unsigned int nb, const int value); void randomSeeds(Image &image, const unsigned int nb, const int value);
@ -57,195 +57,195 @@ void randomSeeds(Image &image, const unsigned int nb, const int value);
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
QApplication application(argc,argv); QApplication application(argc,argv);
ViewerType viewer; ViewerType viewer;
// Appel aux méthodes des exercices.
if (argc > 2)
{
std::stringstream ssAlgo;
ssAlgo << std::string(argv[1]);
std::stringstream ssFile; // Appel aux méthodes des exercices.
ssFile << std::string(argv[2]); if (argc > 2)
if (ssAlgo.str() == "Sandbox") {
imageSandbox(viewer, ssFile.str()); std::stringstream ssAlgo;
else if (ssAlgo.str() == "DT") ssAlgo << std::string(argv[1]);
transformeeEnDistance(viewer, ssFile.str());
} std::stringstream ssFile;
else ssFile << std::string(argv[2]);
{ if (ssAlgo.str() == "Sandbox")
std::cout << "Les paramètres n'a pas été fourni." << std::endl; imageSandbox(viewer, ssFile.str());
std::cout << "startCode <paramètre = {Sandbox | DT}> <nom du fichier>" << std::endl; else if (ssAlgo.str() == "DT")
return 0; transformeeEnDistance(viewer, ssFile.str());
} }
else
return application.exec(); {
std::cout << "Les paramètres n'a pas été fourni." << std::endl;
std::cout << "startCode <paramètre = {Sandbox | DT}> <nom du fichier>" << std::endl;
return 0;
}
return application.exec();
} }
/** /**
* Cette fonction vous permettra de commencer à pratiquer avec le chargement d'objets * Cette fonction vous permettra de commencer à pratiquer avec le chargement d'objets
* volumiques. Les parcourir, retrouver les valeurs affectées à chaque voxel et les * volumiques. Les parcourir, retrouver les valeurs affectées à chaque voxel et les
* les modifier. * les modifier.
* \param Visualisateur à utiliser. * \param Visualisateur à utiliser.
* \param Nom du fichier. * \param Nom du fichier.
* *
*/ */
void imageSandbox(ViewerType& viewer, std::string filename) void imageSandbox(ViewerType& viewer, std::string filename)
{ {
// Lance le visusalisateur. // Lance le visusalisateur.
viewer.show(); viewer.show();
//Chargement d'une image dans une structure de données ImageContainerBySTLVector.
std::string inputFilename = examplesPath + "/" + filename;
Image3D image = GenericReader<Image3D>::import(inputFilename);
// Obtention du domaine (taille) de l'image chargée. //Chargement d'une image dans une structure de données ImageContainerBySTLVector.
Z3i::Domain initialDomain = image.domain(); std::string inputFilename = examplesPath + "/" + filename;
Image3D image = GenericReader<Image3D>::import(inputFilename);
// Définition du gradient des couleurs. // Obtention du domaine (taille) de l'image chargée.
GradientColorMap<long> gradient( 0,30); Z3i::Domain initialDomain = image.domain();
gradient.addColor(Color::Red);
gradient.addColor(Color::Yellow);
gradient.addColor(Color::Green);
gradient.addColor(Color::Cyan);
gradient.addColor(Color::Blue);
gradient.addColor(Color::Magenta);
gradient.addColor(Color::Red);
float min = 0.0; // Définition du gradient des couleurs.
float max = 0.0; GradientColorMap<long> gradient( 0,30);
gradient.addColor(Color::Red);
gradient.addColor(Color::Yellow);
gradient.addColor(Color::Green);
gradient.addColor(Color::Cyan);
gradient.addColor(Color::Blue);
gradient.addColor(Color::Magenta);
gradient.addColor(Color::Red);
for(Z3i::Domain::ConstIterator it= image.domain().begin(), float min = 0.0;
itend = image.domain().end(); it != itend; ++it) float max = 0.0;
{
if (image(*it) > 0) for(Z3i::Domain::ConstIterator it= image.domain().begin(),
viewer << *it; itend = image.domain().end(); it != itend; ++it)
} {
if (image(*it) > 0)
viewer << *it;
}
viewer << SetMode3D(image.className(), "BoundingBox");
viewer << ViewerType::updateDisplay;
viewer << SetMode3D(image.className(), "BoundingBox");
viewer << ViewerType::updateDisplay;
} }
/** /**
* Fonction de la transformée en distance à partir de quelques points germes. * Fonction de la transformée en distance à partir de quelques points germes.
* La distance est calculée à partir de chaque point. Donc, la distance dans un * La distance est calculée à partir de chaque point. Donc, la distance dans un
* voxel est la distance minimale à tous les points germes. * voxel est la distance minimale à tous les points germes.
* \param le visualisateur à utiliser. * \param le visualisateur à utiliser.
* \param Nom du fichier. * \param Nom du fichier.
* *
*/ */
void transformeeEnDistance(ViewerType& viewer, std::string filename) void transformeeEnDistance(ViewerType& viewer, std::string filename)
{ {
// Affichage de la visualisation. // Affichage de la visualisation.
viewer.show(); viewer.show();
// Nombre du fichier à charger. // Nombre du fichier à charger.
std::string inputFilename = examplesPath + "/" + filename; std::string inputFilename = examplesPath + "/" + filename;
// Création du type d'image. // Création du type d'image.
//Default image selector = STLVector //Default image selector = STLVector
typedef ImageSelector<Z3i::Domain, unsigned char>::Type Image; typedef ImageSelector<Z3i::Domain, unsigned char>::Type Image;
//Chargement du fichier image dans la structure. //Chargement du fichier image dans la structure.
Image image = VolReader<Image>::importVol( inputFilename ); Image image = VolReader<Image>::importVol( inputFilename );
// Obtention du domaine (taille) de l'image. // Obtention du domaine (taille) de l'image.
Z3i::Domain domain = image.domain(); Z3i::Domain domain = image.domain();
Image imageSeeds ( domain); Image imageSeeds ( domain);
for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it) for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
(*it)=1; (*it)=1;
//imageSeeds.setValue(p0, 0 ); //imageSeeds.setValue(p0, 0 );
randomSeeds(imageSeeds, 70, 0); randomSeeds(imageSeeds, 70, 0);
typedef functors::SimpleThresholdForegroundPredicate<Image> Predicate;
Predicate aPredicate(imageSeeds,0);
// Création de type et de l'objet pour appliquer la transformée.
typedef DistanceTransformation<Z3i::Space,Predicate, Z3i::L2Metric> DTL2;
DTL2 dtL2(&domain, &aPredicate, &Z3i::l2Metric);
// Detection des distances minimales et maximales. typedef functors::SimpleThresholdForegroundPredicate<Image> Predicate;
unsigned int min = 0; Predicate aPredicate(imageSeeds,0);
unsigned int max = 0;
for(DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(),
itend=dtL2.constRange().end();
it!=itend;
++it)
{
if( (*it) < min )
min=(*it);
if( (*it) > max )
max=(*it);
}
//Spécification des gradients de couleur pour la visualisation.
GradientColorMap<long> gradient( 0,30);
gradient.addColor(Color::Red);
gradient.addColor(Color::Yellow);
gradient.addColor(Color::Green);
gradient.addColor(Color::Cyan);
gradient.addColor(Color::Blue);
gradient.addColor(Color::Magenta);
gradient.addColor(Color::Red);
// Affectation du mode de visualisation 3D. // Création de type et de l'objet pour appliquer la transformée.
viewer << SetMode3D( (*(domain.begin())).className(), "Paving" ); typedef DistanceTransformation<Z3i::Space,Predicate, Z3i::L2Metric> DTL2;
DTL2 dtL2(&domain, &aPredicate, &Z3i::l2Metric);
// Parcours de tous les voxels de l'image avec un iterateur sur le domaine. // Detection des distances minimales et maximales.
for(Z3i::Domain::ConstIterator it = domain.begin(), itend=domain.end(); unsigned int min = 0;
it!=itend; unsigned int max = 0;
++it) for(DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(),
{ itend=dtL2.constRange().end();
it!=itend;
++it)
{
if( (*it) < min )
min=(*it);
if( (*it) > max )
max=(*it);
}
// Calcul de la transformée en distance pour le voxel courant. //Spécification des gradients de couleur pour la visualisation.
double valDist= dtL2( (*it) ); GradientColorMap<long> gradient( 0,30);
gradient.addColor(Color::Red);
gradient.addColor(Color::Yellow);
gradient.addColor(Color::Green);
gradient.addColor(Color::Cyan);
gradient.addColor(Color::Blue);
gradient.addColor(Color::Magenta);
gradient.addColor(Color::Red);
// Calcul du gradient de couleur pour cette distance. // Affectation du mode de visualisation 3D.
Color c= gradient(valDist); viewer << SetMode3D( (*(domain.begin())).className(), "Paving" );
viewer << CustomColors3D(Color((float)(c.red()),
(float)(c.green()), // Parcours de tous les voxels de l'image avec un iterateur sur le domaine.
(float)(c.blue(),205)), for(Z3i::Domain::ConstIterator it = domain.begin(), itend=domain.end();
Color((float)(c.red()), it!=itend;
(float)(c.green()), ++it)
(float)(c.blue()),205)); {
// Le viewer reçoit le prochain voxel pour visualisation.
if (image(*it) > 0) // Calcul de la transformée en distance pour le voxel courant.
viewer << *it ; double valDist= dtL2( (*it) );
}
// Calcul du gradient de couleur pour cette distance.
//viewer << ClippingPlane(0,1,0, -40) << Viewer3D<>::updateDisplay; Color c= gradient(valDist);
// Mise à jour du visualisateur après le parcours de tous le voxels. viewer << CustomColors3D(Color((float)(c.red()),
viewer<< Viewer3D<>::updateDisplay; (float)(c.green()),
(float)(c.blue(),205)),
Color((float)(c.red()),
(float)(c.green()),
(float)(c.blue()),205));
// Le viewer reçoit le prochain voxel pour visualisation.
if (image(*it) > 0)
viewer << *it ;
}
//viewer << ClippingPlane(0,1,0, -40) << Viewer3D<>::updateDisplay;
// Mise à jour du visualisateur après le parcours de tous le voxels.
viewer<< Viewer3D<>::updateDisplay;
} }
/** /**
* Cette fonction genère un ensemble de points afin de les placer * Cette fonction genère un ensemble de points afin de les placer
* dans le volume comme les germes de la transformée en distance. * dans le volume comme les germes de la transformée en distance.
* \param image. * \param image.
* \param nombre de germes. * \param nombre de germes.
* \param value à affecter comme seuil. * \param value à affecter comme seuil.
* *
*/ */
template<typename Image> template<typename Image>
void randomSeeds(Image &image, const unsigned int nb, const int value) void randomSeeds(Image &image, const unsigned int nb, const int value)
{ {
typename Image::Point p, low = image.domain().lowerBound(); typename Image::Point p, low = image.domain().lowerBound();
typename Image::Vector ext; typename Image::Vector ext;
srand ( time(NULL) ); srand ( time(NULL) );
ext = image.extent(); ext = image.extent();
for (unsigned int k = 0 ; k < nb; k++) for (unsigned int k = 0 ; k < nb; k++)
{ {
for (unsigned int dim = 0; dim < Image::dimension; dim++) for (unsigned int dim = 0; dim < Image::dimension; dim++)
p[dim] = rand() % (ext[dim]) + low[dim]; p[dim] = rand() % (ext[dim]) + low[dim];
image.setValue(p, value); image.setValue(p, value);
} }
} }
// // // //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////