OpenWalnut  1.5.0dev
WMWriteTracts.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <fstream>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 #include "WMWriteTracts.h"
31 #include "WMWriteTracts.xpm"
32 #include "core/common/WPropertyHelper.h"
33 #include "core/dataHandler/io/WWriterFiberVTK.h"
34 #include "core/kernel/WKernel.h"
35 
36 W_LOADABLE_MODULE( WMWriteTracts )
37 
39  WModule()
40 {
41 }
42 
44 {
45 }
46 
47 std::shared_ptr< WModule > WMWriteTracts::factory() const
48 {
49  return std::shared_ptr< WModule >( new WMWriteTracts() );
50 }
51 
52 const char** WMWriteTracts::getXPMIcon() const
53 {
54  return WMWriteTracts_xpm;
55 }
56 
57 const std::string WMWriteTracts::getName() const
58 {
59  return "Write Tracts";
60 }
61 
62 const std::string WMWriteTracts::getDescription() const
63 {
64  return "Writes tracts either from a cluster or from a WDataSetFibers to a file";
65 }
66 
68 {
69  m_clusterIC = WModuleInputData< const WFiberCluster >::createAndAdd( shared_from_this(), "clusterInput", "A set of tracts behind the WFiberCluster" ); // NOLINT line length
70  m_tractIC = WModuleInputData< const WDataSetFibers >::createAndAdd( shared_from_this(), "tractInput", "A dataset of tracts" );
71 
73 }
74 
76 {
77  m_savePath = m_properties->addProperty( "Save Path", "Where to save the result", boost::filesystem::path( "/no/such/file" ) );
79  m_run = m_properties->addProperty( "Save", "Start saving", WPVBaseTypes::PV_TRIGGER_READY );
80 
81  m_fileTypeSelectionsList = std::shared_ptr< WItemSelection >( new WItemSelection() );
82  m_fileTypeSelectionsList->addItem( "VTK fib", "Stores the fibers in the VTK line format." );
83  m_fileTypeSelectionsList->addItem( "json", "" );
84  m_fileTypeSelectionsList->addItem( "json2", "" );
85  m_fileTypeSelectionsList->addItem( "json triangles", "" );
86  m_fileTypeSelectionsList->addItem( "POVRay Cylinders", "Stores the fibers as cylinders in a POVRay SDL file." );
87 
88  m_fileTypeSelection = m_properties->addProperty( "File type", "file type.", m_fileTypeSelectionsList->getSelectorFirst(),
89  boost::bind( &WMWriteTracts::fileTypeChanged, this )
90  );
92 
93  m_povrayOptions = m_properties->addPropertyGroup( "POVRay Options", "Options for the POVRay Exporter." );
94  m_povrayOptions->setHidden( true );
95  m_povrayTubeDiameter = m_povrayOptions->addProperty( "Tube Diameter",
96  "The tube diameter. Each fibers is represented as a tube with spheres as connections between them",
97  0.25 );
98  m_povrayTubeDiameter->setMin( 0.001 );
99  m_povrayTubeDiameter->setMax( 2.0 );
100  m_povrayRadiosity = m_povrayOptions->addProperty( "Enable Radiosity",
101  "Enable POVRay's radiosity renderer. Creates more realistic lighting but is very slow.",
102  false );
103  m_povraySaveOnlyNth = m_povrayOptions->addProperty( "Save Every n'th", "Option allows thinning the data. This is useful in cases were fast"
104  " rendering is needed.", 1 );
105  m_povraySaveOnlyNth->setMin( 1 );
106  m_povraySaveOnlyNth->setMax( 1000 );
107 
109 }
110 
112 {
113  m_moduleState.add( m_clusterIC->getDataChangedCondition() );
114  m_moduleState.add( m_tractIC->getDataChangedCondition() );
115  m_moduleState.add( m_run->getCondition() );
116 
117  ready();
118 
119  while( !m_shutdownFlag() )
120  {
121  debugLog() << "Waiting for data ...";
123 
124  if( !m_clusterIC->getData() && !m_tractIC->getData() )
125  {
126  continue;
127  }
128 
129  if( m_run->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
130  {
131  debugLog() << "Start saving fibers: " << m_savePath->get();
132  switch( m_fileTypeSelection->get( true ).getItemIndexOfSelected( 0 ) )
133  {
134  case 0:
135  {
136  WWriterFiberVTK w( m_savePath->get(), true );
137  if( m_clusterIC->getData() )
138  {
139  w.writeFibs( m_clusterIC->getData()->getDataSetReference() );
140  }
141  else if( m_tractIC->getData() )
142  {
143  w.writeFibs( m_tractIC->getData() );
144  }
145  }
146  break;
147  case 1:
148  saveJson();
149  break;
150  case 2:
151  saveJson2();
152  break;
153  case 3:
155  break;
156  case 4:
157  if( m_tractIC->getData() )
158  {
159  savePOVRay( m_tractIC->getData() );
160  }
161  break;
162  default:
163  debugLog() << "this shouldn't be reached";
164  break;
165  }
166  debugLog() << "Finished saving fibers.";
168  }
169  }
170 }
171 
173 {
174  std::shared_ptr< const WDataSetFibers > ds = m_tractIC->getData();
175 
176  if( !ds )
177  {
178  return false;
179  }
180 
181  if( ds->getVertices()->size() == 0 )
182  {
183  WLogger::getLogger()->addLogMessage( "Will not write file that contains 0 vertices.", "Write Tracts", LL_ERROR );
184  return false;
185  }
186 
187  const char* c_file = m_savePath->get().string().c_str();
188  std::ofstream dataFile( c_file, std::ios_base::binary );
189 
190  if( dataFile )
191  {
192  WLogger::getLogger()->addLogMessage( "opening file", "Write Tracts", LL_DEBUG );
193  }
194  else
195  {
196  WLogger::getLogger()->addLogMessage( "open file failed" + m_savePath->get().string() , "Write Tracts", LL_ERROR );
197  return false;
198  }
199 
200  dataFile.setf( std::ios_base::fixed );
201  dataFile.precision( 3 );
202 
203  WLogger::getLogger()->addLogMessage( "start writing file", "Write Tracts", LL_DEBUG );
204 
205  dataFile << ( "{\n" );
206 
207  dataFile << ( " \"vertices\" : [" );
208  std::shared_ptr<std::vector<float> > verts = ds->getVertices();
209  float fValue;
210  for( size_t i = 0; i < ( verts->size() - 1 ) / 3; ++i )
211  {
212  fValue = verts->at( i * 3 );
213  dataFile << fValue << ",";
214  fValue = verts->at( i * 3 + 1 );
215  dataFile << fValue << ",";
216  fValue = verts->at( i * 3 + 2 );
217  dataFile << fValue << ",";
218  }
219  fValue = verts->at( verts->size() - 3 );
220  dataFile << fValue << ",";
221  fValue = verts->at( verts->size() - 2 );
222  dataFile << fValue << ",";
223  fValue = verts->at( verts->size() - 1 );
224  dataFile << fValue << "],\n";
225 
226  dataFile << ( " \"normals\" : [" );
227  std::shared_ptr<std::vector<float> > tangents = ds->getTangents();
228  for( size_t i = 0; i < tangents->size() - 1; ++i )
229  {
230  fValue = tangents->at( i );
231  dataFile << fValue << ",";
232  }
233  fValue = tangents->at( tangents->size() - 1 );
234  dataFile << fValue << "],\n";
235 
236  dataFile << ( " \"colors\" : [" );
237  std::shared_ptr< std::vector< float > > colors = ds->getColorScheme( "Global Color" )->getColor();
238  for( size_t i = 0; i < colors->size() - 3; i += 3 )
239  {
240  fValue = colors->at( i );
241  dataFile << fValue << ",";
242  fValue = colors->at( i + 1 );
243  dataFile << fValue << ",";
244  fValue = colors->at( i + 2 );
245  dataFile << fValue << ",1.0,";
246  }
247  fValue = colors->at( colors->size() - 3 );
248  dataFile << fValue << ",";
249  fValue = colors->at( colors->size() - 2 );
250  dataFile << fValue << ",";
251  fValue = colors->at( colors->size() - 1 );
252  dataFile << fValue << ",1.0],\n";
253 
254  int iValue;
255  dataFile << ( " \"indices\" : [" );
256  std::shared_ptr<std::vector<size_t> > lengths = ds->getLineLengths();
257  for( size_t i = 0; i < lengths->size() - 1; ++i )
258  {
259  iValue = lengths->at( i );
260  dataFile << iValue << ",";
261  }
262  iValue = lengths->at( lengths->size() - 1 );
263  dataFile << iValue << "]";
264 
265  dataFile << "\n}";
266 
267  dataFile.close();
268  WLogger::getLogger()->addLogMessage( "saving done", "Write Tracts", LL_DEBUG );
269  return true;
270 }
271 
273 {
274  std::shared_ptr< const WDataSetFibers > ds = m_tractIC->getData();
275 
276  if( !ds )
277  {
278  return false;
279  }
280 
281  if( ds->getVertices()->size() == 0 )
282  {
283  WLogger::getLogger()->addLogMessage( "Will not write file that contains 0 vertices.", "Write Tracts", LL_ERROR );
284  return false;
285  }
286 
287  const char* c_file = m_savePath->get().string().c_str();
288  std::ofstream dataFile( c_file, std::ios_base::binary );
289 
290  if( dataFile )
291  {
292  WLogger::getLogger()->addLogMessage( "opening file", "Write Tracts", LL_DEBUG );
293  }
294  else
295  {
296  WLogger::getLogger()->addLogMessage( "open file failed" + m_savePath->get().string() , "Write Tracts", LL_ERROR );
297  return false;
298  }
299 
300  dataFile.setf( std::ios_base::fixed );
301  dataFile.precision( 3 );
302 
303  //**************************************************************************************
304  // create arrays;
305 
306  std::vector<float> nVertices;
307  std::vector<float> nNormals;
308  std::vector<float> nColors;
309  std::vector<size_t> nIndices;
310 
311  std::shared_ptr<std::vector<size_t> > starts = ds->getLineStartIndexes();
312  std::shared_ptr<std::vector<size_t> > lengths = ds->getLineLengths();
313 
314 
315  std::shared_ptr<std::vector<float> > verts = ds->getVertices();
316  std::shared_ptr<std::vector<float> > tangents = ds->getTangents();
317  std::shared_ptr< std::vector< float > > colors = ds->getColorScheme( "Global Color" )->getColor();
318 
319  for( size_t k = 0; k < lengths->size(); ++k )
320  {
321  size_t newLength = 0;
322  for( size_t i = starts->at( k ); i < ( starts->at( k ) + lengths->at( k ) ); ++i )
323  {
324  if( i % 2 == 0 )
325  {
326  nVertices.push_back( verts->at( i * 3 ) );
327  nVertices.push_back( verts->at( i * 3 + 1 ) );
328  nVertices.push_back( verts->at( i * 3 + 2 ) );
329 
330  nNormals.push_back( - tangents->at( i * 3 ) );
331  nNormals.push_back( - tangents->at( i * 3 + 1 ) );
332  nNormals.push_back( tangents->at( i * 3 + 2 ) );
333 
334  nColors.push_back( colors->at( i * 3 ) );
335  nColors.push_back( colors->at( i * 3 + 1 ) );
336  nColors.push_back( colors->at( i * 3 + 2 ) );
337  nColors.push_back( 1.0 );
338 
339  ++newLength;
340  }
341  }
342  nIndices.push_back( newLength );
343  }
344 
345 
346 
347  WLogger::getLogger()->addLogMessage( "start writing file", "Write Tracts", LL_DEBUG );
348 
349  dataFile << ( "{\n" );
350 
351  dataFile << ( " \"vertices\" : [" );
352 
353  float fValue;
354  for( size_t i = 0; i < nVertices.size() - 1 ; ++i )
355  {
356  fValue = nVertices[i];
357  dataFile << fValue << ",";
358  }
359  fValue = verts->at( verts->size() - 1 );
360  dataFile << fValue << "],\n";
361 
362  dataFile << ( " \"normals\" : [" );
363 
364  for( size_t i = 0; i < nNormals.size() - 1; ++i )
365  {
366  fValue = nNormals[i];
367  dataFile << fValue << ",";
368  }
369  fValue = nNormals[nNormals.size() - 1];
370  dataFile << fValue << "],\n";
371 
372  dataFile << ( " \"colors\" : [" );
373 
374  for( size_t i = 0; i < nColors.size()- 1; ++i )
375  {
376  fValue = nColors[i];
377  dataFile << fValue << ",";
378  }
379  fValue = nColors[nColors.size() - 1];
380  dataFile << fValue << ",1.0],\n";
381 
382  int iValue;
383  dataFile << ( " \"indices\" : [" );
384 
385  for( size_t i = 0; i < nIndices.size() - 1; ++i )
386  {
387  iValue = nIndices[i];
388  dataFile << iValue << ",";
389  }
390  iValue = nIndices[nIndices.size() - 1];
391  dataFile << iValue << "]";
392 
393  dataFile << "\n}";
394 
395  dataFile.close();
396  WLogger::getLogger()->addLogMessage( "saving done", "Write Tracts", LL_DEBUG );
397  return true;
398 }
399 
400 
402 {
403  std::shared_ptr< const WDataSetFibers > ds = m_tractIC->getData();
404 
405  if( !ds )
406  {
407  return false;
408  }
409 
410  if( ds->getVertices()->size() == 0 )
411  {
412  WLogger::getLogger()->addLogMessage( "Will not write file that contains 0 vertices.", "Write Tracts", LL_ERROR );
413  return false;
414  }
415 
416  const char* c_file = m_savePath->get().string().c_str();
417  std::ofstream dataFile( c_file, std::ios_base::binary );
418 
419  if( dataFile )
420  {
421  WLogger::getLogger()->addLogMessage( "opening file", "Write Tracts", LL_DEBUG );
422  }
423  else
424  {
425  WLogger::getLogger()->addLogMessage( "open file failed" + m_savePath->get().string() , "Write Tracts", LL_ERROR );
426  return false;
427  }
428 
429  dataFile.precision( 7 );
430 
431  WLogger::getLogger()->addLogMessage( "start writing file", "Write Tracts", LL_DEBUG );
432 
433  dataFile << ( "{\n" );
434 
435  dataFile << ( " \"vertices\" : [" );
436  std::shared_ptr<std::vector<float> > verts = ds->getVertices();
437  float fValue0;
438  float fValue1;
439  float fValue2;
440  for( size_t i = 0; i < verts->size() - 3; ++i )
441  {
442  fValue0 = verts->at( i );
443  i += 1;
444  fValue1 = verts->at( i );
445  i += 1;
446  fValue2 = verts->at( i );
447  dataFile << fValue0 << "," << fValue1 << "," << fValue2 << ",";
448  dataFile << fValue0 << "," << fValue1 << "," << fValue2 << ",";
449  }
450  fValue0 = verts->at( verts->size() - 3 );
451  fValue1 = verts->at( verts->size() - 2 );
452  fValue2 = verts->at( verts->size() - 1 );
453  dataFile << fValue0 << "," << fValue1 << "," << fValue2 << ",";
454  dataFile << fValue0 << "," << fValue1 << "," << fValue2 << "],\n";
455 
456  dataFile << ( " \"indices\" : [" );
457  std::shared_ptr<std::vector<size_t> > starts = ds->getLineStartIndexes();
458  std::shared_ptr<std::vector<size_t> > lengths = ds->getLineLengths();
459 
460  int counter = 0;
461  for( size_t i = 0; i < lengths->size(); ++i )
462  {
463  for( size_t k = 0; k < lengths->at( i ); ++k )
464  {
465  dataFile << counter << "," << counter + 1 << "," << counter + 2 << ",";
466  dataFile << counter + 1 << "," << counter + 3 << "," << counter + 2 << ",";
467  }
468  }
469 
470  dataFile << "\n}";
471 
472  dataFile.close();
473  WLogger::getLogger()->addLogMessage( "saving done", "Write Tracts", LL_DEBUG );
474  return true;
475 }
476 
477 bool WMWriteTracts::savePOVRay( std::shared_ptr< const WDataSetFibers > fibers ) const
478 {
479  // open file
480  boost::filesystem::path meshFile( m_savePath->get() );
481  std::string fnPath = meshFile.parent_path().string();
482  std::string fnBase = meshFile.stem().string();
483  std::string fnExt = meshFile.extension().string();
484 
485  // construct the filenames
486  // the meshfile
487  std::string fnMesh = fnBase + ".mesh" + fnExt;
488  std::string fnScene = fnBase + ".scene" + fnExt;
489 
490  // absolute paths
491  std::string fnMeshAbs = fnPath + "/" + fnMesh;
492  std::string fnSceneAbs = fnPath + "/" + fnScene;
493 
494  debugLog() << "Opening " << fnMeshAbs << " for writing the mesh data.";
495  std::ofstream dataFile( fnMeshAbs.c_str(), std::ios_base::binary );
496  if( !dataFile )
497  {
498  errorLog() << "Opening " << fnMeshAbs << " failed.";
499  return false;
500  }
501 
502  // needed arrays for iterating the fibers
503  WDataSetFibers::IndexArray fibStart = fibers->getLineStartIndexes();
504  WDataSetFibers::LengthArray fibLen = fibers->getLineLengths();
505  WDataSetFibers::VertexArray fibVerts = fibers->getVertices();
506  WDataSetFibers::TangentArray fibTangents = fibers->getTangents();
507 
508  // get current color scheme - the mode is important as it defines the number of floats in the color array per vertex.
509  WDataSetFibers::ColorScheme::ColorMode fibColorMode = fibers->getColorScheme()->getMode();
510  debugLog() << "Color mode is " << fibColorMode << ".";
511  WDataSetFibers::ColorArray fibColors = fibers->getColorScheme()->getColor();
512 
513  // for each fiber:
514  debugLog() << "Iterating over all fibers.";
515 
516  // find min and max
517  double minX = wlimits::MAX_DOUBLE;
518  double minY = wlimits::MAX_DOUBLE;
519  double minZ = wlimits::MAX_DOUBLE;
520  double maxX = wlimits::MIN_DOUBLE;
521  double maxY = wlimits::MIN_DOUBLE;
522  double maxZ = wlimits::MIN_DOUBLE;
523 
524  size_t currentStart = 0;
525  size_t increment = m_povraySaveOnlyNth->get();
526 
527  std::shared_ptr< WProgress > progress1( new WProgress( "Converting fibers", fibStart->size() / increment ) );
528  m_progress->addSubProgress( progress1 );
529  for( size_t fidx = 0; fidx < fibStart->size(); fidx += increment )
530  {
531  ++*progress1;
532 
533  // the start vertex index
534  size_t sidx = fibStart->at( fidx ) * 3;
535  size_t csidx = fibStart->at( fidx ) * fibColorMode;
536 
537  // the length of the fiber
538  size_t len = fibLen->at( fidx );
539 
540  // walk along the fiber
541  WVector3d lastvert( fibVerts->at( sidx ),
542  fibVerts->at( sidx + 1 ),
543  fibVerts->at( sidx + 2 ) );
544  for( size_t k = 1; k < len; ++k )
545  {
546  // grab vector and color
547  WVector3d vert( fibVerts->at( ( 3 * k ) + sidx ),
548  fibVerts->at( ( 3 * k ) + sidx + 1 ),
549  fibVerts->at( ( 3 * k ) + sidx + 2 ) );
550  WColor color( fibColors->at( ( fibColorMode * k ) + csidx + ( 0 % fibColorMode ) ),
551  fibColors->at( ( fibColorMode * k ) + csidx + ( 1 % fibColorMode ) ),
552  fibColors->at( ( fibColorMode * k ) + csidx + ( 2 % fibColorMode ) ),
553  ( fibColorMode == WDataSetFibers::ColorScheme::RGBA ) ?
554  fibColors->at( ( fibColorMode * k ) + csidx + ( 3 % fibColorMode ) ) : 1.0 );
555 
556  if( vert.x() > maxX )
557  maxX = vert.x();
558  if( vert.y() > maxY )
559  maxY = vert.y();
560  if( vert.z() > maxZ )
561  maxZ = vert.z();
562  if( vert.x() < minX )
563  minX = vert.x();
564  if( vert.y() < minY )
565  minY = vert.y();
566  if( vert.z() < minZ )
567  minZ = vert.z();
568 
569  // write it in POVRay style
570  dataFile << "cylinder" << std::endl <<
571  "{" << std::endl <<
572  " <" << lastvert.x() << "," << lastvert.y() << "," << lastvert.z() << ">," <<
573  "<" << vert.x() << "," << vert.y() << "," << vert.z() << ">,Diameter" << std::endl <<
574  " pigment{color rgb <" << color.x() << "," << color.y() << "," << color.z() << ">}" << std::endl <<
575  " transform MoveToCenter" << std::endl <<
576  "}" << std::endl;
577  dataFile << "sphere {" << std::endl <<
578  " <" << vert.x() << "," << vert.y() << "," << vert.z() << ">,Diameter" << std::endl <<
579  " pigment{ color rgb <" << color.x() << "," << color.y() << "," << color.z() << ">}" << std::endl <<
580  " transform MoveToCenter" << std::endl <<
581  "}" << std::endl;
582 
583  lastvert = vert;
584  }
585  currentStart += len;
586  }
587 
588  double sizeX = maxX - minX;
589  double sizeY = maxY - minY;
590  double sizeZ = maxZ - minZ;
591  double mX = minX + ( sizeX / 2.0 );
592  double mY = minY + ( sizeY / 2.0 );
593  double mZ = minZ + ( sizeZ / 2.0 );
594 
595  // done writing mesh. Close
596  infoLog() << "Done. Closing " << fnMesh << ".";
597  dataFile.close();
598  progress1->finish();
599 
600  debugLog() << "Opening " << fnSceneAbs << " for writing.";
601  std::ofstream dataFileScene( fnSceneAbs.c_str(), std::ios_base::binary );
602  if( !dataFileScene )
603  {
604  errorLog() << "Opening " << fnSceneAbs << " failed.";
605  return false;
606  }
607 
608  // write some head data
609  dataFileScene << "#version 3.6;" << std::endl << std::endl;
610 
611  dataFileScene << "// run with povray -w800 -h600 -Q0 fibsLarge.scene.pov " << std::endl <<
612  "// * this creates a fast preview of the scene with a resolution of 800x600." << std::endl <<
613  "// * the Q parameter defines the quality Q0 means plain colors. Q11 is best, including radiosity." << std::endl << std::endl;
614 
615  if( m_povrayRadiosity->get() )
616  {
617  dataFileScene << "global_settings {" << std::endl <<
618  " ambient_light 0" << std::endl << std::endl <<
619  " radiosity {" << std::endl <<
620  " pretrace_start 0.08" << std::endl <<
621  " pretrace_end 0.005" << std::endl <<
622  " count 350" << std::endl <<
623  " error_bound 0.15" << std::endl <<
624  " recursion_limit 2" << std::endl <<
625  " }" << std::endl <<
626  "}" << std::endl << std::endl;
627  }
628 
629  dataFileScene << "// Enable Phong lighting for all the geometry" << std::endl;
630  dataFileScene << "#default{" << std::endl <<
631  " finish{" << std::endl <<
632  " ambient 0" << std::endl <<
633  " phong 1" << std::endl <<
634  " // reflection 0.9 " << std::endl <<
635  " }" << std::endl <<
636  "}" << std::endl << std::endl;
637 
638  // save camera and add a light
639  double camX = 0;
640  double camY = sizeY;
641  double camZ = 0;
642 
643  dataFileScene << "#declare MoveToCenter = transform{ translate < " << -mX << ", " << -mY << ", " << -mZ << " > };" << std::endl;
644  dataFileScene << "#declare CamPosition = < " << camX << ", " << camY << ", " << camZ << " >;" << std::endl << std::endl;
645  dataFileScene << "// Tube diameter" << std::endl;
646  dataFileScene << "#declare Diameter = " << m_povrayTubeDiameter->get() << ";" << std::endl << std::endl;
647 
648  // this camera should produce a direct front view. The user surely needs to modify the camera
649  dataFileScene << "camera {" << std::endl <<
650  " orthographic angle 45" << std::endl <<
651  " location CamPosition" << std::endl <<
652  " right 1.33*x" << std::endl <<
653  " // use this with 1280x1024" << std::endl <<
654  " // right 1.25*x" << std::endl <<
655  " up y " << std::endl <<
656  " look_at < 0, 0, 0 >" << std::endl <<
657  "}" << std::endl << std::endl;
658  // headlight
659  dataFileScene << "light_source {" << std::endl <<
660  " CamPosition" << std::endl <<
661  " color rgb <1.0, 1.0, 1.0>" << std::endl <<
662  "}" << std::endl << std::endl;
663 
664  // do not forget the mesh
665  dataFileScene << "#include \"" << fnMesh << "\"" << std::endl;
666 
667  // done. Close
668  infoLog() << "Done.";
669  dataFileScene.close();
670  return true;
671 }
672 
674 {
675  if( m_fileTypeSelection->get().getItemIndexOfSelected( 0 ) == 4 )
676  {
677  m_povrayOptions->setHidden( false );
678  }
679  else
680  {
681  m_povrayOptions->setHidden( true );
682  }
683 }
684 
virtual void wait() const
Wait for the condition.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
ColorMode
different kinds of color arrays can be used in this class.
std::shared_ptr< std::vector< size_t > > IndexArray
Index list indexing fibers in VertexArray in terms of vertex numbers.
std::shared_ptr< std::vector< float > > ColorArray
Colors for each vertex in VertexArray.
std::shared_ptr< std::vector< float > > TangentArray
Tangents at each vertex in VertexArray.
std::shared_ptr< std::vector< size_t > > LengthArray
Lengths of fibers in terms of vertices.
std::shared_ptr< std::vector< float > > VertexArray
List of vertex coordinates in term of components of vertices.
A class containing a list of named items.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
Definition: WLogger.cpp:84
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
Definition: WLogger.cpp:64
This module writes the tracts of either a fiber cluster or directly out of a WDataSetFibers at its co...
Definition: WMWriteTracts.h:46
std::shared_ptr< WModuleInputData< const WDataSetFibers > > m_tractIC
Input connector for writing directly tracts to a file.
std::shared_ptr< WModuleInputData< const WFiberCluster > > m_clusterIC
Input connector for writing the tracts out of a WFiberCluster to a file.
WMWriteTracts()
Constructs an instance to write tracts to a file.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
bool savePOVRay(std::shared_ptr< const WDataSetFibers > fibers) const
Saves the fiber tracts as POVRAY SDL.
virtual void moduleMain()
Entry point after loading the module.
bool saveJson() const
Store the mesh in a json (javascript object notation) file.
std::shared_ptr< WItemSelection > m_fileTypeSelectionsList
A list of file type selection types.
WPropGroup m_povrayOptions
Groups all the options for the povray exporter.
bool saveJson2() const
Store the mesh in a json (javascript object notation) file using only every other vertex.
WPropTrigger m_run
Button to start saving.
virtual void properties()
Initialize the properties for this module.
WPropInt m_povraySaveOnlyNth
Allows thinning of the data.
WPropFilename m_savePath
Path where tracts should be stored.
WPropDouble m_povrayTubeDiameter
The tube diameter in povray export.
virtual void connectors()
Initialize the connectors this module is using.
WPropBool m_povrayRadiosity
Enables radiosity renderer in povray.
virtual const std::string getDescription() const
Gives back a description of this module.
void fileTypeChanged()
Handles updates in filetype property.
virtual const std::string getName() const
Gives back the name of this module.
virtual ~WMWriteTracts()
Destructs this instance.
WPropSelection m_fileTypeSelection
Selection property for file types.
bool saveJsonTriangles() const
Store the mesh in a json (javascript object notation) file.
ValueT & z()
Access z element of vector.
ValueT & y()
Access y element of vector.
ValueT & x()
Access x element of vector.
static PtrType createAndAdd(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Convenience method to create a new instance of this in data connector with proper type and add it to ...
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
virtual void properties()
Initialize properties in this function.
Definition: WModule.cpp:212
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
Definition: WModule.cpp:575
std::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WModule.h:640
void ready()
Call this whenever your module is ready and can react on property changes.
Definition: WModule.cpp:505
WConditionSet m_moduleState
The internal state of the module.
Definition: WModule.h:703
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
Definition: WModule.cpp:570
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
Definition: WModule.h:652
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
Definition: WModule.cpp:565
virtual void connectors()
Initialize connectors in this function.
Definition: WModule.cpp:208
Class managing progress inside of modules.
Definition: WProgress.h:42
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Writes a FiberVTK file.
void writeFibs(std::shared_ptr< const WDataSetFiberVector > fiberDS) const
Writes a WDataSetFiberVector down to the previousely given file.
@ PV_TRIGGER_TRIGGERED
Trigger property: got triggered.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
const double MAX_DOUBLE
Maximum double value.
Definition: WLimits.cpp:31
const double MIN_DOUBLE
Positive minimum double value.
Definition: WLimits.cpp:36