Skip to content

Commit

Permalink
Merge pull request #448 from kerautret/MeshViewerEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoeurjo authored Feb 16, 2023
2 parents 288cdca + cf5e09f commit fc743cb
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 69 deletions.
10 changes: 10 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# DGtalTools 1.4 (beta)

- *visualisation*
- meshViewer: new options to change the default background color, to
load camera settings at startup, to change at startup the light
source mode attached or not to the camera and improve transparency
process at startup rendering. It includes a fix of the
-customColorMesh for obj mesh and add new possibilities to custom
the color of each mesh given as input. It also includes a fix and
some simplications of the option --doSnapShotAndExit. (Bertrand
Kerautret
[#448](https://github.com/DGtal-team/DGtalTools/pull/448))

- *volumetric*
- volReSample: fix the impossibility to export to vol when ITK is activated
Expand Down
58 changes: 35 additions & 23 deletions visualisation/3dVolViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ using namespace Z3i;
--colorMesh UINT ... set the color of Mesh (given from displayMesh option) : r g b a
-d,--doSnapShotAndExit save display snapshot into file. Notes that the camera setting is set by default according the last saved configuration (use SHIFT+Key_M to save current camera setting in the Viewer3D). If the camera setting was not saved it will use the default camera setting.
-t,--transparency UINT=255 change the defaukt transparency
--useLastCameraSetting use the last camera setting of the user (i.e if a .qglviewer.xml file is present in the current directory)
@endcode
Expand Down Expand Up @@ -211,10 +212,13 @@ int main( int argc, char** argv )
std::string displayMesh;
std::string snapShotFile;
std::vector<unsigned int> colorMesh;
std::vector<unsigned int > customBGColor;

string inputType {""};
bool interactiveDisplayVoxCoords {false};
bool transIntensity {false};
bool transIntensitySq {false};
bool useLastCamSet {false};

app.add_option("-i,--input,1", inputFileName, "vol file (.vol, .longvol .p3d, .pgm3d and if WITH_ITK is selected: dicom, dcm, mha, mhd). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255." )
->required()
Expand All @@ -231,13 +235,15 @@ int main( int argc, char** argv )
app.add_option("--displayMesh", displayMesh, "display a Mesh given in OFF or OFS format.");
app.add_option("--colorMesh", colorMesh, "set the color of Mesh (given from displayMesh option) : r g b a ")
->expected(4);
app.add_flag("--doSnapShotAndExit,-d",snapShotFile, "save display snapshot into file. Notes that the camera setting is set by default according the last saved configuration (use SHIFT+Key_M to save current camera setting in the Viewer3D). If the camera setting was not saved it will use the default camera setting." );
app.add_option("--doSnapShotAndExit,-d", snapShotFile, "save display snapshot into file. Notes that the camera setting is set by default according the last saved configuration (use SHIFT+Key_M to save current camera setting in the Viewer3D). If the camera setting was not saved it will use the default camera setting.");
app.add_option("--customBGColor,-b", customBGColor, "set the R, G, B, A components of the colors of the sdp view")
->expected(3);
app.add_option("--transparency,-t", transparency, "change the defaukt transparency", true);
app.add_flag("--transIntensity",transIntensity , "Used vocel intensity to define transparency valeue");
app.add_flag("--transIntensitySq",transIntensitySq , "Used squared vocel intensity to define transparency valeue");

app.add_flag("--interactiveDisplayVoxCoords,-c", interactiveDisplayVoxCoords, " by using this option the coordinates can be displayed after selection (shift+left click on voxel).");
app.get_formatter()->column_width(40);
app.add_flag("--useLastCameraSetting", useLastCamSet, "use the last camera setting of the user (i.e if a .qglviewer.xml file is present in the current directory)");
app.get_formatter()->column_width(40);
CLI11_PARSE(app, argc, argv);
// END parse command line using CLI ----------------------------------------------

Expand All @@ -264,7 +270,14 @@ int main( int argc, char** argv )
Image3D_D imageD = Image3D_D(d);
Image3D_I imageI = Image3D_I(d);
Image image = Image(d);

if (customBGColor.size() == 3)
{
viewer.myDefaultBackgroundColor = DGtal::Color(customBGColor[0],
customBGColor[1],
customBGColor[2], 255);
viewer.update();
viewer.draw();
}
if(extension != "sdp")
{
unsigned int numDisplayed=0;
Expand Down Expand Up @@ -324,25 +337,24 @@ int main( int argc, char** argv )
}

viewer << Viewer3D<>::updateDisplay;
if(snapShotFile != "")
{
// Appy cleaning just save the last snap
if(!viewer.restoreStateFromFile())
if(snapShotFile != "" )
{
viewer.update();
}
std::string extension = snapShotFile.substr(snapShotFile.find_last_of(".") + 1);
std::string basename = snapShotFile.substr(0, snapShotFile.find_last_of("."));
for(int i=0; i< viewer.snapshotCounter()-1; i++){
std::stringstream s;
s << basename << "-"<< setfill('0') << setw(4)<< i << "." << extension;
trace.info() << "erase temp file: " << s.str() << std::endl;
remove(s.str().c_str());
}
std::stringstream s;
s << basename << "-"<< setfill('0') << setw(4)<< viewer.snapshotCounter()-1 << "." << extension;
rename(s.str().c_str(), snapShotFile.c_str());
return 0;
// Recover mesh position
viewer.restoreStateFromFile();
viewer.saveSnapshot(QString(snapShotFile.c_str()), true);
return 0;
}

if (useLastCamSet)
{
viewer.restoreStateFromFile();
}
// First display transparency improve
viewer.sortTriangleFromCamera();
viewer.sortQuadFromCamera();
viewer.sortSurfelFromCamera();
viewer.sortPolygonFromCamera();
viewer << Viewer::updateDisplay;
trace.info() << "[display ready]"<< std::endl;
return application.exec();
}
124 changes: 78 additions & 46 deletions visualisation/meshViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ using namespace DGtal;
--SDPradius FLOAT=0.5 change the ball radius to display a set of discrete points (used with displaySDP option)
-s,--displaySDP TEXT add the display of a set of discrete points as ball of radius 0.5.
-A,--addAmbientLight FLOAT add an ambient light for better display (between 0 and 1).
-d,--doSnapShotAndExit TEXT save display snapshot into file. Notes that the camera setting is set by default according the last saved configuration (use SHIFT+Key_M to save current camera setting in the Viewer3D). If the camera setting was not saved it will use the default camera setting.
-b,--customBGColor UINT x 3 set the R, G, B components of the colors of the background color.
-d,--doSnapShotAndExit TEXT save display snapshot into file. Notes that the camera setting is set by default according the last saved configuration (use SHIFT+Key_M to save current camera setting in the Viewer3D). If the camera setting was not saved it will use the default camera setting.
-c,--useLastCameraSetting use the last camera setting of the user (i.e if a .qglviewer.xml file is present in the current directory)
-l,--fixLightToScene Fix light source to scence instead to camera
-n,--invertNormal invert face normal vectors.
-v,--drawVertex draw the vertex of the mesh
@endcode
Expand Down Expand Up @@ -110,10 +112,9 @@ class CustomViewer3D: public Viewer3D<>
Viewer3D<>::init();
Viewer3D<>::setKeyDescription ( Qt::Key_I, "Display mesh informations about #faces, #vertices" );
Viewer3D<>::setGLDoubleRenderingMode(false);
if(mySaveSnap){
QObject::connect(this, SIGNAL(drawFinished(bool)), this, SLOT(saveSnapshot(bool)));
}

}

virtual void keyPressEvent(QKeyEvent *e){
bool handled = false;
if( e->key() == Qt::Key_I)
Expand All @@ -137,9 +138,14 @@ class CustomViewer3D: public Viewer3D<>
};

public:
void changeDefaultBGColor(const DGtal::Color &col)
{
myDefaultBackgroundColor = col;
Viewer3D<>::update();
Viewer3D<>::draw();
}
std::string myInfoDisplay = "No information loaded...";
bool myIsDisplayingInfoMode = false;
bool mySaveSnap = false;
DGtal::Z3i::RealPoint centerMesh;
};

Expand Down Expand Up @@ -170,6 +176,7 @@ int main( int argc, char** argv )
std::vector<unsigned int > customColorMesh;
std::vector<unsigned int > customColorSDP;
std::vector<unsigned int > customLineColor;
std::vector<unsigned int > customBGColor;
std::vector<unsigned int > vectFieldIndices = {0,1,2,3,4,5};
std::string displayVectorField;

Expand All @@ -178,6 +185,8 @@ int main( int argc, char** argv )
double ballRadius {0.5};
bool invertNormal {false};
bool drawVertex {false};
bool useLastCamSet {false};
bool fixLightToScene {false};
float ambiantLight {0.0};


Expand Down Expand Up @@ -205,10 +214,14 @@ int main( int argc, char** argv )
app.add_option("--SDPradius", ballRadius, "change the ball radius to display a set of discrete points (used with displaySDP option)", true);
app.add_option("--displaySDP,-s", filenameSDP, "add the display of a set of discrete points as ball of radius 0.5.");
app.add_option("--addAmbientLight,-A", ambiantLight, "add an ambient light for better display (between 0 and 1)." );
app.add_option("--customBGColor,-b", customBGColor, "set the R, G, B components of the colors of the background color.")
->expected(3);
app.add_option("--doSnapShotAndExit,-d", snapshotFile, "save display snapshot into file. Notes that the camera setting is set by default according the last saved configuration (use SHIFT+Key_M to save current camera setting in the Viewer3D). If the camera setting was not saved it will use the default camera setting.");
app.add_flag("--useLastCameraSetting,-c", useLastCamSet, "use the last camera setting of the user (i.e if a .qglviewer.xml file is present in the current directory)");
app.add_flag("--fixLightToScene,-l", fixLightToScene, "Fix light source to scence instead to camera");
app.add_flag("--invertNormal,-n", invertNormal, "invert face normal vectors.");
app.add_flag("--drawVertex,-v", drawVertex, "draw the vertex of the mesh");


app.get_formatter()->column_width(40);
CLI11_PARSE(app, argc, argv);
Expand All @@ -224,24 +237,11 @@ int main( int argc, char** argv )

if( customColorMesh.size() != 0 )
{
if(customColorMesh.size()!=4 && customColorMesh.size()!=8 )
if(customColorMesh.size()<4 )
{
trace.error() << "colors specification should contain R,G,B and Alpha values"<< std::endl;
}
if( customColorMesh.size() >= 4)
{
meshColorR = customColorMesh[0];
meshColorG = customColorMesh[1];
meshColorB = customColorMesh[2];
meshColorA = customColorMesh[3];
}
if(customColorMesh.size() == 8)
{
meshColorRLine = customColorMesh[4];
meshColorGLine = customColorMesh[5];
meshColorBLine = customColorMesh[6];
meshColorALine = customColorMesh[7];
}

}

if(customColorSDP.size() == 4)
Expand All @@ -254,7 +254,6 @@ int main( int argc, char** argv )

QApplication application(argc,argv);
CustomViewer3D viewer;
viewer.mySaveSnap = snapshotFile != "";
if(snapshotFile != "")
{
viewer.setSnapshotFileName(QString(snapshotFile.c_str()));
Expand All @@ -266,7 +265,11 @@ int main( int argc, char** argv )
viewer.show();
viewer.myGLLineMinWidth = lineWidth;
viewer.setGLScale(sx, sy, sz);

if (customBGColor.size() == 3){
viewer.changeDefaultBGColor(DGtal::Color(customBGColor[0],
customBGColor[1],
customBGColor[2], 255));
}
if(ambiantLight != 0.0)
{
GLfloat lightAmbientCoeffs [4] = {ambiantLight,ambiantLight, ambiantLight, 1.0f};
Expand All @@ -280,6 +283,16 @@ int main( int argc, char** argv )
{
Mesh<DGtal::Z3i::RealPoint> aMesh(customColorMesh.size() != 4 && customColorMesh.size() != 8);
aMesh << inputFileNames[i];
// for obj mesh by default the mesh color face are not necessary uniform.
if (aMesh.isStoringFaceColors() && customColorMesh.size() >= 4 ){
if ( i*8 < customColorMesh.size() ) {meshColorR = customColorMesh[i*8];}
if ( i*8+1< customColorMesh.size() ) {meshColorG = customColorMesh[i*8+1];}
if ( i*8+2 < customColorMesh.size() ) {meshColorB = customColorMesh[i*8+2];}
if ( i*8+3 < customColorMesh.size() ) {meshColorA = customColorMesh[i*8+3];}
for (unsigned int j = 0; j < aMesh.nbFaces(); j++){
aMesh.setFaceColor(j, Color(meshColorR, meshColorG, meshColorB, meshColorA));
}
}
vectMesh.push_back(aMesh);
}
DGtal::Z3i::RealPoint centerMeshes;
Expand Down Expand Up @@ -317,10 +330,21 @@ int main( int argc, char** argv )
}
}

viewer << CustomColors3D(Color(meshColorRLine, meshColorGLine, meshColorBLine, meshColorALine),
Color(meshColorR, meshColorG, meshColorB, meshColorA));
for(unsigned int i=0; i<vectMesh.size(); i++){
viewer << vectMesh[i];
for(unsigned int i=0; i<vectMesh.size(); i++){
if ( i*8 < customColorMesh.size() ) {meshColorR = customColorMesh[i*8];}
if ( i*8+1< customColorMesh.size() ) {meshColorG = customColorMesh[i*8+1];}
if ( i*8+2 < customColorMesh.size() ) {meshColorB = customColorMesh[i*8+2];}
if ( i*8+3 < customColorMesh.size() ) {meshColorA = customColorMesh[i*8+3];}
if ( i*8+4 < customColorMesh.size() ) {meshColorALine = customColorMesh[i*8+4];}
if ( i*8+5< customColorMesh.size() ) {meshColorBLine = customColorMesh[i*8+5];}
if ( i*8+6 < customColorMesh.size() ) {meshColorRLine = customColorMesh[i*8+6];}
if ( i*8+7 < customColorMesh.size() ) {meshColorALine = customColorMesh[i*8+7];}

viewer << CustomColors3D(Color(meshColorRLine, meshColorGLine, meshColorBLine,
meshColorALine),
Color(meshColorR, meshColorG, meshColorB, meshColorA));

viewer << vectMesh[i];
}

if(drawVertex){
Expand Down Expand Up @@ -358,27 +382,35 @@ int main( int argc, char** argv )
ss << "# faces: " << std::fixed << nbFaces << " #vertex: " << nbVertex ;
viewer.myInfoDisplay = ss.str();
viewer << CustomViewer3D::updateDisplay;
if (fixLightToScene)
{
viewer.setLightModeFixToCamera(false, false);
}

if (useLastCamSet)
{
viewer.restoreStateFromFile();
}
else
{
// useful in non interactive case in order to retain the default camera settings (that are not saved in case of process kill).
viewer.saveStateToFile();
}
// First display transparency improve
viewer.sortTriangleFromCamera();
viewer.sortQuadFromCamera();
viewer.sortSurfelFromCamera();
viewer.sortPolygonFromCamera();
viewer << CustomViewer3D::updateDisplay;

if(snapshotFile != "" )
{
// Appy cleaning just save the last snap
if(!viewer.restoreStateFromFile())
{
viewer.update();
}
std::string extension = snapshotFile.substr(snapshotFile.find_last_of(".") + 1);
std::string basename = snapshotFile.substr(0, snapshotFile.find_last_of("."));
for(int i=0; i< viewer.snapshotCounter()-1; i++){
std::stringstream s;
s << basename << "-"<< setfill('0') << setw(4)<< i << "." << extension;
trace.info() << "erase temp file: " << s.str() << std::endl;
remove(s.str().c_str());
}

std::stringstream s;
s << basename << "-"<< setfill('0') << setw(4)<< viewer.snapshotCounter()-1 << "." << extension;
rename(s.str().c_str(), snapshotFile.c_str());
// Recover mesh position
viewer.restoreStateFromFile();
viewer.saveSnapshot(QString(snapshotFile.c_str()), true);
return 0;
}

trace.info() << "[display ready]"<< std::endl;

return application.exec();
}

0 comments on commit fc743cb

Please sign in to comment.