30 #include "DGtal/base/Common.h"
31 #include "DGtal/base/BasicFunctors.h"
32 #include "DGtal/helpers/StdDefs.h"
33 #include "DGtal/io/readers/GenericReader.h"
34 #include "DGtal/io/viewers/Viewer3D.h"
35 #include "DGtal/io/DrawWithDisplay3DModifier.h"
36 #include "DGtal/io/readers/PointListReader.h"
37 #include "DGtal/io/readers/MeshReader.h"
39 #include "DGtal/io/Color.h"
40 #include "DGtal/io/colormaps/GradientColorMap.h"
41 #include "DGtal/images/ImageSelector.h"
46 using namespace DGtal;
104 template <
typename Space = DGtal::Z3i::Space,
typename KSpace = DGtal::Z3i::KSpace>
115 QObject::connect(
this, SIGNAL(drawFinished(
bool)),
this, SLOT(saveSnapshot(
bool)));
121 typedef ViewerSnap<>
Viewer;
126 template<
typename TImage>
128 displayCoordsCallBack(
void* viewer,
int name,
void* data )
130 TImage *image = (TImage *) data;
131 std::stringstream ss;
134 if (image->domain().isInside(p)){
135 ss <<
"Selected intensity: " << (*image)(p) <<
"p " << p[0] <<
" "<< p[1] <<
" " << p[2] ;
136 ((
Viewer *) viewer)->displayMessage(QString(ss.str().c_str()), 100000);
142 template <
typename TImage>
144 processDisplay(ViewerSnap<> &viewer, TImage &image,
145 const typename TImage::Value &thresholdMin,
146 const typename TImage::Value &thresholdMax,
147 unsigned int numDisplayedMax,
148 unsigned int transparency,
149 bool useTransIntensity=
false,
150 bool interDisplay=
false,
151 bool squaredTransp=
false)
153 Domain domain = image.domain();
155 unsigned int numDisplayed = 0;
156 gradient.addColor(Color::Blue);
157 gradient.addColor(Color::Green);
158 gradient.addColor(Color::Yellow);
159 gradient.addColor(Color::Red);
160 typename TImage::Value varInt = 0;
161 if (useTransIntensity){
162 varInt = thresholdMax-thresholdMin;
166 if (useTransIntensity){
167 trInt = ((float)(image( (*it) )-thresholdMin)/(
float)varInt);
169 typename TImage::Value val= image( (*it) );
170 if(numDisplayed > numDisplayedMax)
173 Color c= gradient(val);
174 if(val<=thresholdMax && val >=thresholdMin)
178 static_cast<unsigned int>(transparency*trInt*(squaredTransp? trInt : 1.0))),
180 static_cast<unsigned int>(transparency*trInt*(squaredTransp? trInt: 1.0))));
200 int main(
int argc,
char** argv )
204 app.description(
"Display volume file as a voxel set by using QGLviewer. \n Example: \n \t 3dVolViewer $DGtal/examples/samples/lobster.vol -m 60 -t 10");
205 std::string inputFileName;
208 double thresholdMin {0};
209 double thresholdMax {255};
210 unsigned int transparency {255};
211 unsigned int numDisplayedMax {500000};
212 std::string displayMesh;
213 std::string snapShotFile;
214 std::vector<unsigned int> colorMesh;
215 std::vector<unsigned int > customBGColor;
217 string inputType {
""};
218 bool interactiveDisplayVoxCoords {
false};
219 bool transIntensity {
false};
220 bool transIntensitySq {
false};
221 bool useLastCamSet {
false};
223 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." )
225 ->check(CLI::ExistingFile);
227 app.add_option(
"--inputType", inputType,
"to specify the input image type (int or double).")
228 -> check(CLI::IsMember({
"int",
"double"}));
230 app.add_option(
"--thresholdMin,-m", thresholdMin,
"threshold min (excluded) to define binary shape.",
true);
231 app.add_option(
"--thresholdMax,-M", thresholdMax,
"threshold max (included) to define binary shape.",
true);
232 app.add_option(
"--rescaleInputMin", rescaleInputMin,
"min value used to rescale the input intensity (to avoid basic cast into 8 bits image).",
true);
233 app.add_option(
"--rescaleInputMax", rescaleInputMax,
"max value used to rescale the input intensity (to avoid basic cast into 8 bits image).",
true);
234 app.add_option(
"--numMaxVoxel,-n", numDisplayedMax,
"set the maximal voxel number to be displayed.");
235 app.add_option(
"--displayMesh", displayMesh,
"display a Mesh given in OFF or OFS format.");
236 app.add_option(
"--colorMesh", colorMesh,
"set the color of Mesh (given from displayMesh option) : r g b a ")
238 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.");
239 app.add_option(
"--customBGColor,-b", customBGColor,
"set the R, G, B, A components of the colors of the sdp view")
241 app.add_option(
"--transparency,-t", transparency,
"change the defaukt transparency",
true);
242 app.add_flag(
"--transIntensity",transIntensity ,
"Used vocel intensity to define transparency valeue");
243 app.add_flag(
"--transIntensitySq",transIntensitySq ,
"Used squared vocel intensity to define transparency valeue");
244 app.add_flag(
"--interactiveDisplayVoxCoords,-c", interactiveDisplayVoxCoords,
" by using this option the coordinates can be displayed after selection (shift+left click on voxel).");
245 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)");
246 app.get_formatter()->column_width(40);
247 CLI11_PARSE(app, argc, argv);
250 QApplication application(argc,argv);
252 Viewer viewer(snapShotFile !=
"");
253 if(snapShotFile !=
""){
254 viewer.setSnapshotFileName(QString(snapShotFile.c_str()));
256 viewer.setWindowTitle(
"simple Volume Viewer");
262 string extension = inputFileName.substr(inputFileName.find_last_of(
".") + 1);
264 std::vector<double> vectValD;
265 std::vector<int> vectValI;
266 std::vector<unsigned char> vectValUC;
270 Image3D_D imageD = Image3D_D(d);
271 Image3D_I imageI = Image3D_I(d);
273 if (customBGColor.size() == 3)
275 viewer.myDefaultBackgroundColor =
DGtal::Color(customBGColor[0],
277 customBGColor[2], 255);
281 if(extension !=
"sdp")
283 unsigned int numDisplayed=0;
286 if (inputType==
"double")
290 trace.
info() <<
"Image loaded: D "<<imageD<< std::endl;
291 processDisplay(viewer, imageD, thresholdMin, thresholdMax, numDisplayedMax, transparency,
292 transIntensity||transIntensitySq, interactiveDisplayVoxCoords, transIntensitySq);
294 else if (inputType==
"int")
297 trace.
info() <<
"Image loaded: "<<image<< std::endl;
298 processDisplay(viewer, imageI, (
int)thresholdMin, (
int)thresholdMax, numDisplayedMax, transparency,
299 transIntensity||transIntensitySq, interactiveDisplayVoxCoords, transIntensitySq);
305 trace.
info() <<
"Image loaded: "<<image<< std::endl;
306 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax, transparency,
307 transIntensity||transIntensitySq, interactiveDisplayVoxCoords, transIntensitySq);
314 trace.
info() <<
"Image loaded: "<<image<< std::endl;
315 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax, transparency,
316 transIntensity||transIntensitySq, interactiveDisplayVoxCoords, transIntensitySq);
319 else if(extension==
"sdp")
322 for(
unsigned int i=0;i< vectVoxels.size(); i++){
323 viewer <<
Z3i::Point(vectVoxels.at(i), functors::Round<>());
326 if(displayMesh !=
"")
328 if(colorMesh.size() != 0)
330 Color c(colorMesh[0], colorMesh[1], colorMesh[2], colorMesh[3]);
331 viewer.setFillColor(c);
339 viewer << Viewer3D<>::updateDisplay;
340 if(snapShotFile !=
"" )
343 viewer.restoreStateFromFile();
344 viewer.saveSnapshot(QString(snapShotFile.c_str()),
true);
350 viewer.restoreStateFromFile();
353 viewer.sortTriangleFromCamera();
354 viewer.sortQuadFromCamera();
355 viewer.sortSurfelFromCamera();
356 viewer.sortPolygonFromCamera();
358 trace.
info() <<
"[display ready]"<< std::endl;
359 return application.exec();
int main(int argc, char **argv)
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
typename Self::Domain Domain
Trace trace(traceWriterTerm)
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())