32 #include "DGtal/base/Common.h"
33 #include "DGtal/base/BasicFunctors.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/io/readers/VolReader.h"
36 #include "DGtal/io/viewers/Viewer3D.h"
37 #include "DGtal/io/DrawWithDisplay3DModifier.h"
38 #include "DGtal/io/readers/PointListReader.h"
39 #include "DGtal/io/readers/MeshReader.h"
40 #include "DGtal/topology/helpers/Surfaces.h"
41 #include "DGtal/topology/SurfelAdjacency.h"
43 #include "DGtal/io/Color.h"
44 #include "DGtal/io/colormaps/GradientColorMap.h"
45 #include "DGtal/io/readers/GenericReader.h"
47 #include "DGtal/io/readers/DicomReader.h"
50 #include "DGtal/images/ImageSelector.h"
54 #include "specificClasses/Viewer3DImage.cpp"
56 #include <boost/program_options/options_description.hpp>
57 #include <boost/program_options/parsers.hpp>
58 #include <boost/program_options/variables_map.hpp>
62 using namespace DGtal;
134 namespace po = boost::program_options;
137 int main(
int argc,
char** argv )
145 po::options_description general_opt(
"Allowed options are ");
146 general_opt.add_options()
147 (
"help,h",
"display this message")
148 (
"input,i", po::value<std::string>(),
"vol file (.vol, .longvol .p3d, .pgm3d and if WITH_ITK is selected: dicom, dcm, mha, mhd) or sdp (sequence of discrete points). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255." )
149 (
"grid",
"draw slice images using grid mode. " )
150 (
"intergrid",
"draw slice images using inter grid mode. " )
151 (
"emptyMode",
"remove the default boundingbox display " )
152 (
"thresholdImage",
"threshold the image to define binary shape" )
153 (
"thresholdMin,m", po::value<int>()->default_value(0),
"threshold min to define binary shape" )
154 (
"thresholdMax,M", po::value<int>()->default_value(255),
"threshold max to define binary shape" )
155 (
"displaySDP,s", po::value<std::string>(),
"display a set of discrete points (.sdp)" )
156 (
"SDPindex", po::value<std::vector <unsigned int> >()->multitoken(),
"specify the sdp index (by default 0,1,2).")
157 (
"SDPball", po::value<double>()->default_value(0.5),
"use balls to display a set of discrete points (used with displaySDP option)")
158 (
"displayMesh", po::value<std::string>(),
"display a Mesh given in OFF or OFS format. " )
159 (
"displayDigitalSurface",
"display the digital surface instead of display all the set of voxels (used with thresholdImage or displaySDP options)" )
160 (
"colorizeCC",
"colorize each Connected Components of the surface displayed by displayDigitalSurface option." )
161 (
"colorSDP,c", po::value<std::vector <int> >()->multitoken(),
"set the color discrete points: r g b a " )
162 (
"colorMesh", po::value<std::vector <int> >()->multitoken(),
"set the color of Mesh (given from displayMesh option) : r g b a " )
163 (
"scaleX,x", po::value<float>()->default_value(1.0),
"set the scale value in the X direction (default 1.0)" )
164 (
"scaleY,y", po::value<float>()->default_value(1.0),
"set the scale value in the Y direction (default 1.0)" )
165 (
"scaleZ,z", po::value<float>()->default_value(1.0),
"set the scale value in the Z direction (default 1.0)")
166 (
"rescaleInputMin", po::value<DGtal::int64_t>()->default_value(0),
"min value used to rescale the input intensity (to avoid basic cast into 8 bits image).")
167 (
"rescaleInputMax", po::value<DGtal::int64_t>()->default_value(255),
"max value used to rescale the input intensity (to avoid basic cast into 8 bits image).")
168 (
"transparency,t", po::value<uint>()->default_value(255),
"transparency") ;
171 po::variables_map vm;
173 po::store(po::parse_command_line(argc, argv, general_opt), vm);
174 }
catch(
const std::exception& ex){
176 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
179 if( !parseOK || vm.count(
"help")||argc<=1)
181 std::cout <<
"Usage: " << argv[0] <<
" [input]\n"
182 <<
"Displays volume file as a voxel set by using QGLviewer"
183 << general_opt <<
"\n";
187 if(! vm.count(
"input"))
189 trace.
error() <<
" The file name was defined" << endl;
192 string inputFilename = vm[
"input"].as<std::string>();
193 int thresholdMin = vm[
"thresholdMin"].as<
int>();
194 int thresholdMax = vm[
"thresholdMax"].as<
int>();
195 unsigned char transp = vm[
"transparency"].as<uint>();
197 QApplication application(argc,argv);
199 float sx = vm[
"scaleX"].as<
float>();
200 float sy = vm[
"scaleY"].as<
float>();
201 float sz = vm[
"scaleZ"].as<
float>();
203 double ballRadius = vm[
"SDPball"].as<
double>();
204 string extension = inputFilename.substr(inputFilename.find_last_of(
".") + 1);
207 if(vm.count(
"emptyMode"))
209 else if(vm.count(
"grid"))
211 else if(vm.count(
"intergrid"))
217 viewer.setWindowTitle(
"simple Volume Viewer");
219 viewer.setGLScale(sx, sy, sz);
230 trace.
info() <<
"Image loaded: "<<image<< std::endl;
231 viewer.setVolImage(&image);
238 viewer << Viewer3D<>::updateDisplay;
239 if(vm.count(
"thresholdImage")){
241 gradient.addColor(Color::Blue);
242 gradient.addColor(Color::Green);
243 gradient.addColor(Color::Yellow);
244 gradient.addColor(Color::Red);
246 unsigned char val= image( (*it) );
247 Color c= gradient(val);
248 if(val<=thresholdMax && val >=thresholdMin){
249 if(!vm.count(
"displayDigitalSurface")){
260 if(vm.count(
"displaySDP")){
261 if(vm.count(
"colorSDP")){
262 std::vector<int> vcol= vm[
"colorSDP"].as<std::vector<int > >();
264 trace.
error() <<
"Not enough parameter: color specification should contains four elements: red, green, blue and alpha values." << std::endl;
267 Color c(vcol[0], vcol[1], vcol[2], vcol[3]);
271 vector<Z3i::Point> vectVoxels;
272 if(vm.count(
"SDPindex")) {
273 std::vector<unsigned int > vectIndex = vm[
"SDPindex"].as<std::vector<unsigned int > >();
274 if(vectIndex.size()!=3){
275 trace.
error() <<
"you need to specify the three indexes of vertex." << std::endl;
282 for(
unsigned int i=0;i< vectVoxels.size(); i++){
283 if(!vm.count(
"displayDigitalSurface")){
284 if(vm.count(
"SDPball")){
285 viewer.addBall (vectVoxels.at(i), ballRadius);
287 viewer << vectVoxels.at(i);
290 set3d.insert(vectVoxels.at(i));
295 if(vm.count(
"displayMesh")){
296 if(vm.count(
"colorMesh")){
297 std::vector<int> vcol= vm[
"colorMesh"].as<std::vector<int > >();
299 trace.
error() <<
"Not enough parameter: color specification should contains four elements: red, green, blue and alpha values." << std::endl;
302 Color c(vcol[0], vcol[1], vcol[2], vcol[3]);
303 viewer.setFillColor(c);
311 if(vm.count(
"displayDigitalSurface")){
313 Point low = domain.
lowerBound(); low[0]=low[0]-1; low[1]=low[1]-1; low[2]=low[2]-1;
314 Point upp = domain.upperBound(); upp[0]=upp[0]+1; upp[1]=upp[1]+1; upp[2]=upp[2]+1;
315 K.
init(low, upp ,
true);
317 vector<vector<SCell> > vectConnectedSCell;
318 trace.
info() <<
"Extracting surface set ... " ;
330 viewer <<
DGtal::SetMode3D(vectConnectedSCell.at(0).at(0).className(),
"Basic");
331 for(
unsigned int i= 0; i <vectConnectedSCell.size(); i++){
332 for(
unsigned int j= 0; j <vectConnectedSCell.at(i).size(); j++){
333 if(vm.count(
"colorizeCC")){
338 }
else if(vm.count(
"colorSDP")){
339 std::vector<int> vcol= vm[
"colorSDP"].as<std::vector<int > >();
340 Color c(vcol[0], vcol[1], vcol[2], vcol[3]);
344 viewer << vectConnectedSCell.at(i).at(j);
349 viewer << Viewer3D<>::updateDisplay;
352 unsigned int maxDist = std::max(std::max(size[2], size[1]), size[0]);
353 viewer.camera()->setPosition(qglviewer::Vec(center[0],center[1],
354 center[2] + 2.0*maxDist));
355 viewer.camera()->setSceneCenter(qglviewer::Vec(center[0],center[1],center[2]));
359 return application.exec();
static const Color Magenta
void addColor(const Color &color)
static const Color Yellow
const Point & lowerBound() const
bool init(const Point &lower, const Point &upper, bool isClosed)
Trace trace(traceWriterTerm)
const Domain & domain() const
typename Self::Point Point
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
typename Self::Domain Domain
void blue(const unsigned char aBlueValue)