MorphoGraphX
ImageData.hpp
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef IMAGE_DATA_H
12 
13 #define IMAGE_DATA_H
14 
15 #include <Config.hpp>
16 
17 #include <ClipRegion.hpp>
18 #include <ColorBar.hpp>
19 #include <Colors.hpp>
20 #include <Geometry.hpp>
21 #include <Mesh.hpp>
22 #include <MGXViewer/qglviewer.h>
23 #include <Misc.hpp>
24 #include <Parms.hpp>
25 #include <Process.hpp>
26 #include <ScaleBar.hpp>
27 #include <Shader.hpp>
28 #include <TransferFunctionDlg.hpp>
29 #include <TransferFunction.hpp>
30 
31 #include <CImg.h>
32 #include <QtGui>
33 #include <string>
34 #include <string.h>
35 
36 namespace mgx {
37 
38  class CutSurf;
39 
40  typedef util::Vector<4, vertex> Point4v;
41  typedef util::Vector<3, GLubyte> Point3GLub;
42 
43  struct UpdateImgDataEvent : public QEvent {
44  UpdateImgDataEvent() : QEvent(QEvent::User) {}
45  };
46 
47  class mgx_EXPORT ImgData : public QObject //, public ImplicitFunction
48  {
49  Q_OBJECT
50  public:
52 
53  static const uint RELOAD_NONE = 0x0;
54  static const uint RELOAD_MAIN = 0x1;
55  static const uint RELOAD_WORK = 0x2;
56  static const uint RELOAD_TRIS = 0x4;
57  static const uint RELOAD_LINES = 0x8;
58  static const uint RELOAD_POS = 0x10;
59  static const uint RELOAD_VBO = 0x20;
60  static const uint UPDATE_SELECTION = 0x40;
61 
62  int StackId;
63 
64  Stack* stack;
65  Mesh* mesh;
66 
67  // Main and stack paramters
68  bool Main16Bit, Work16Bit;
69 
70  // General
71  bool needUpdateLines;
72  bool needUpdateTris;
73 
74  gui::TransferFunctionDlg* workTransferDlg, *mainTransferDlg, *surfTransferDlg, *heatTransferDlg;
75  // Function defining the color of the pixels
76  std::vector<TransferFunction::Colorf> MainColorMap; // Color map for the main data
77  std::vector<TransferFunction::Colorf> WorkColorMap; // Color map for the work data
78  std::vector<TransferFunction::Colorf> SurfColorMap; // Color map for the surface
79  std::vector<TransferFunction::Colorf> HeatColorMap; // Color map for the heatmap
80  // If true, a new texture need to be sent for the colormap
81  bool newMainColorMap, newWorkColorMap, newSurfColorMap, newHeatColorMap;
82  std::vector<double> MainHist; // Histogram of the main data
83  std::vector<double> WorkHist; // Histogram of the working data
84  std::vector<double> SurfHist; // Histogram of the surface data
85  std::vector<double> HeatHist; // Histogram of the surface data
86  std::pair<double, double> mainBounds;
87  std::pair<double, double> workBounds;
88 
89  GLuint mainDataTexId; // 3D texture Id for main stack
90  GLuint workDataTexId; // 3D texture Id for work stack
91  GLuint dataTexColor; // 3D texture color
92  GLuint surfTexId; // 1D texture map for surface colors.
93  GLuint heatTexId; // 1D texture map for heatmap colors.
94  GLuint imgTexId; // 2D texture map for surface from an image
95  GLuint mcmapTexId, wcmapTexId; // 1D texture map for volume colors.
96  GLuint labelTexId; // 1D texture map to color indexed texture for labels
97  graph::vertex_identity_t lineId; // Last id when drawing lines
98  std::set<uint> selectV; // List of selected vertices
99 
100  Colors::ColorType MeshColor;
101  Colors::ColorType MeshBorderColor;
102  // Colors::ColorType MeshPointColor;
103  Colors::ColorType MeshSelectColor;
104 
105  int TCount; // Triangle count
106  int LCount; // Line count
107  int VCount; // Vertex count
108 
109  // Helper arrays for vertex buffer obejects
110  std::vector<vertex> idVA; // Vertex ids, used to find selection in triangle mode (!MeshSelect)
111  std::vector<vertex> pidVA; // Point vtx ids, used to find selection in point mode (MeshSelect)
112  std::unordered_map<vertex, uint> vMap; // Pointer into idVA by vertex
113 
114  // VBO arrays
115  std::vector<Point3f> posVA; // Vertex positions
116  std::vector<Point3f> nrmlVA; // Vertex normals
117  std::vector<Point3GLub> selVA; // Unique colors for triangle selection
118  std::vector<Point3f> texVA; // Mesh labels, signal, and heat
119  std::vector<Point2f> imgVA; // Image texture coordinates
120 
121  std::vector<uint> lineVA; // Indices for drawing lines
122  std::vector<uint> lbrdVA; // Indices for drawing border lines
123  std::vector<uint> lcellVA; // Indices for drawing cell border lines
124  std::vector<uint> lselVA; // Indices for drawing selected lines
125 
126  std::vector<uint> pbrdVA; // Indices for drawing border points
127  std::vector<uint> pcellVA; // Indices for drawing cell border points
128  std::vector<uint> pselVA; // Indices for drawing selected points
129  std::vector<Point3f> pntsVA; // Vertices for drawing points
130  std::vector<Point3GLub> pcolVA; // Colors for points
131  std::vector<Point3GLub> pselcolVA; // Selection colors for points
132 
133  GLuint posVAid; // VBO object ids
134  GLuint nrmlVAid;
135  GLuint selVAid;
136  GLuint texVAid;
137  GLuint imgVAid;
138 
139  GLuint pntsVAid;
140  GLuint pcolVAid;
141  GLuint pselVAid;
142 
143  GLubyte* texMap; // Texture map to memory
144 
145  // Parameters from stack file
146  QString Section;
147  std::vector<QString> ImageFiles;
148 
149  QWidget* parent; // Parent widget
150  float min, max;
151 
152  // Vectors to make heat maps
153  float labelWallBordMin;
154  float labelWallBordMax;
155  QString sigStr; // Description of heat map
156  IntPoint3fMap LabC; // Label Centers
157  Point3u clipDo; // Which clipping planes are selected
158  Point4f pn[6]; // Clip planes tranformed into frame coordinates
159  HVec4F Hpn; // Host vector for planes for cuda
160  Matrix4d frm; // Frame matrix
161  Matrix4d clm[3]; // Clip plane matrices
162  float pixelRadius; // Radius in frame coordinates of pixel edit tool
163  BoundingBox3f bBox; // Bounding box
164  BoundingBox3i bBoxTex; // Bounding box for texture update
165  int marchLabel; // Label for maching cubes on segmented stack
166 
167  bool LoadMeshAdd;
168  float meshShift; // Shift for the mesh, relative to the scene radius
169 
170  // Variables to marching cubes (for eval)
171  HVecUS* marchData;
172 
173  bool EnableRotate;
174 
175  bool readOnce; // Used for parameter loading
176 
177  // Parameters shared by all instances
178  static int ClearColor;
179  static uint Slices;
180  static uint TileCount;
181  static Point3u MaxTexSize;
182  static float ZOffset;
183 
184  static float DrawNormals;
185  static float DrawOffset;
186  static float DrawZeroLabels;
187  static float DrawNhbds;
188  static bool DeleteBadVertex;
189  static bool FillWorkData;
190  static bool SeedStack;
191  static int PixelEditRadius;
192  static int PixelEditMaxPix;
193  static std::vector<Colorf> LabelColors;
194  bool LabelColorsChanged;
195 
196  static bool MeshSelect;
197  static ScaleBar scaleBar;
198  static Colorbar colorBar;
199 
200  static float MeshPointSize;
201  static float MeshLineWidth;
202 
203  bool changed; // Has the stack (mesh) changed
204  bool pixelsChanged; // Changed flag for pixel editing
205 
206  public:
207  ImgData(int id, QWidget* _parent = 0);
208 
209  ~ImgData();
210 
211  void init(Stack* s, Mesh* m);
212 
213  // Set the internal format of the data
214  void setWork16Bit(bool val);
215  void setMain16Bit(bool val);
216 
217  // Set parameters for function
218  void readParms(util::Parms& parms, QString section);
219 
220  // Set parameters for function
221  void writeParms(QTextStream& pout, QString section);
222 
223  // Get the frame with or without additional transform
224  qglviewer::ManipulatedFrame& getFrame() {
225  return stack->getFrame();
226  }
227 
228  // Get the main frame
229  qglviewer::ManipulatedFrame& getMainFrame() {
230  return stack->frame();
231  }
232 
233  // Get the transform frame
234  qglviewer::ManipulatedFrame& getTransFrame() {
235  return stack->trans();
236  }
237 
238  // Marching cubes evaluation function
239  int eval(Point3f p);
240 
241  // Draw stack data
242  void drawStack(Shader* shader);
243 
244  // Set the file containing the current color map
245  void setColorMap(const QString& pth, bool work);
246 
247  // Update heat histogram
248  void updateHeatHistogram();
249  // Update surface histogram
250  void updateSurfHistogram();
251  // Update work histogram
252  void updateWorkHistogram();
253  // Update main histogram
254  void updateMainHistogram();
255 
256  // Edit the transfer function
257  void editMainTransferFunction(QWidget* parent = 0);
258  void editWorkTransferFunction(QWidget* parent = 0);
259  void editSurfTransferFunction(QWidget* parent = 0);
260  void editHeatTransferFunction(QWidget* parent = 0);
261 
262  // Update the color map texture
263  void updateSurfColorMap() {
264  updateColorMap(newSurfColorMap, SurfColorMap, mesh->surfFct());
265  }
266  void updateHeatColorMap() {
267  updateColorMap(newHeatColorMap, HeatColorMap, mesh->heatFct());
268  }
269  void updateWorkColorMap() {
270  updateColorMap(newWorkColorMap, WorkColorMap, stack->work()->transferFct());
271  }
272  void updateMainColorMap() {
273  updateColorMap(newMainColorMap, MainColorMap, stack->main()->transferFct());
274  }
275  void updateColorMap(bool& newColorMap, std::vector<TransferFunction::Colorf>& ColorMap,
276  const TransferFunction& transferFct);
277 
278  // Setup color map to use in draw
279  void setupSurfColorMap() {
280  setupColorMap(newSurfColorMap, surfTexId, SurfColorMap, Shader::AT_SURF_TEX);
281  }
282  void setupHeatColorMap() {
283  setupColorMap(newHeatColorMap, heatTexId, HeatColorMap, Shader::AT_HEAT_TEX);
284  }
285  void setupMainColorMap() {
286  setupColorMap(newMainColorMap, mcmapTexId, MainColorMap, Shader::AT_CMAP_TEX);
287  }
288  void setupMainColorMap2() {
289  setupColorMap(newMainColorMap, mcmapTexId, MainColorMap, Shader::AT_SECOND_CMAP_TEX);
290  }
291  void setupWorkColorMap() {
292  setupColorMap(newWorkColorMap, wcmapTexId, WorkColorMap, Shader::AT_CMAP_TEX);
293  }
294  void setupWorkColorMap2() {
295  setupColorMap(newWorkColorMap, wcmapTexId, WorkColorMap, Shader::AT_SECOND_CMAP_TEX);
296  }
297  void setupLabelColorMap()
298  {
299  std::vector<TransferFunction::Colorf> empty;
300  bool nonew = false;
301  setupColorMap(nonew, labelTexId, empty, Shader::AT_LABEL_TEX);
302  }
303  void setupColorMap(bool& newColorMap, GLuint& cmapTexId, const std::vector<TransferFunction::Colorf>& ColorMap,
304  Shader::ActiveTextures activeTex);
305 
306  // Draw mesh wireframe, select renders point only in AUX buffer
307  void drawMesh(bool select);
308 
309  // Draw lines joining corresponding vertices
310  void drawVertexVertexLine(ImgData* stack); // added by ALR
311 
312  // Draw cell axis
313  void drawCellAxis(); // added by ALR
314 
315  // Draw Bounding Box around the stack
316  void drawBBox();
317 
318  // Setup the uniforms and textures to render 3D data
319  void setup3DRenderingData(Shader* shader);
320 
321  // Draw mesh shaded, select renders unique colors in AUX buffer
322  void drawSurf(bool select, Shader* texture_shader = 0, Shader* label_shader = 0, Shader* volume_shader = 0);
323 
324  bool showOpaqueSurface() {
325  return mesh->isSurfaceVisible() and !mesh->blending();
326  }
327 
328  bool showTransparentSurface() {
329  return mesh->isSurfaceVisible() && mesh->blending() && (mesh->opacity() > 0.0);
330  }
331 
332  void setupVolumeShader(Shader& shader, int pos);
333 
334  // Mark margin vertices and border labels
335  void markMargin(std::set<vertex>& M, bool remborders);
336 
337  // Check if the graph has matching in-out edges
338  void chkGraph();
339 
340  // Subdivide bisect, recursively divide to prevent degenerate triangles
341  void subdivideBisect(vertex v1, vertex v2, vertex v3);
342 
343  // Get all vertices close to a set of border vertices
344  void markBorder(float borderSize);
345 
346  // Get signal and areas by label
347  void getLabelMaps(float borderSize);
348 
349  // Test if border triangle
350  bool isBordTriangle(int label, vertex v, vertex n, vertex m, IntIntPair& rp);
351 
352  // Setup data for clipping test
353  void getClipTestData(ClipRegion& clip1, ClipRegion& clip2, ClipRegion& clip3);
354 
355  // Test if a point (in image coordinates) is inside clipping planes
356  bool clipTest(const Point3i& ip);
357 
358  // Routine to connect neighborhoods when loading keyence data
359  void makeNhbd(std::vector<vertex>& vtxs);
360  void makeNhbd(vvgraph& S, vertex v, vertex n1, vertex n2, vertex n3, vertex n4);
361  void makeNhbd(vvgraph& S, vertex v, vertex n1, vertex n2, vertex n3, vertex n4, vertex n5, vertex n6);
362 
363  // Save surface for ICP
364  int getPointsICP(std::vector<Point3f>& pts, qglviewer::Frame& frame);
365 
366  // Reset stack data
367  void resetStack();
368 
369  // Reset mesh data
370  void resetMesh();
371 
372  // Initialize controls
373  void initControls(QWidget* viewer);
374 
375  // Determine if triangle is labeled, all vertices labelled and the same (or -1 = boundary)
376  int getLabel(vertex v1, vertex v2, vertex v3, bool useParentLabel = true) const;
377 
378  // Texture management
379  void unloadTex();
380  void loadTex();
381  void reloadLabelTex();
382  void reloadMainTex(const BoundingBox3i& bbox = BoundingBox3i());
383  void reloadWorkTex(const BoundingBox3i& bbox = BoundingBox3i());
384  void reloadTex(GLuint texId);
385  void updateTex(GLuint texId, BoundingBox3i bBox);
386  void initTex();
387  void bind3DTex(GLuint texId, Shader::ActiveTextures atexId = Shader::AT_TEX3D);
388  void bind2DTex(GLuint texId);
389  void unbind3DTex();
390  void unbind2DTex();
391  void loadImgTex(const QImage& image);
392 
393  // Fill selected color with current label (bucket icon)
394  void fillLabel(int label, int currlabel);
395 
396  // Set parent label
397  void setParent(int label, int parentLabel);
398 
399  // Select the vertices for given label
400  void selectLabel(int label, int repeat = 0);
401 
402  // Unselect the vertices for given label
403  void unselectLabel(int label);
404 
405  // Select the vertices for given parent
406  void selectParent(int label, int repeat = 0);
407 
408  // Unselect the vertices for given parent
409  void unselectParent(int label);
410 
411  // Select connected vertices
412  void selectConnected(std::vector<uint>& vlist, bool unselect);
413 
414  // Put label on a list of vertices (a triangle)
415  void addSeed(int label, std::vector<uint>& vlist);
416 
417  // Fill selection with current
418  void fillSelect(int label);
419 
420  // Delete selected vertices
421  void deleteLabel(int label);
422 
423  // void markLine(const vertex &s, const vertex &d);
424 
425  // Set margins and normals and count triangles for VBOs
426  void marginNormalsVBOs();
427 
428  // Update triangle texture coords
429  void updateTris();
430  void updateTris(vvgraph& T);
431 
432  // Update points and lines
433  void updateLines();
434 
435  // Update positions
436  void updatePos();
437 
438  // Fill the vertex array
439  void fillVBOs();
440 
441  // Correct the selection
442  void correctSelection(bool inclusive);
443 
444  // Update the selection array
445  void updateSelection();
446 
447  // Update Color and texture vertex array
448  void updColorVBOs();
449 
450  // Update VBO texture coordinate values
451  // RSS: Is this used?
452  // void updTexCoord();
453 
454  // Update a list of vertex positions in the VBO
455  void updPos(std::set<uint>& vlist, bool points);
456 
457  // Find selected triangle in triangle select mode (!MeshSelect)
458  void findSelectTriangle(uint x, uint y, std::vector<uint>& vlist, int& label, bool useParentLabel = true);
459 
460  // Find selected point in mesh select mode (MeshSelect)
461  int findSelectPoint(uint x, uint y);
462 
463  // Average a list of vertices to find select point
464  bool findSeedPoint(uint x, uint y, CutSurf& cutSurf, Point3f& p);
465 
466  // Clear mesh selection
467  void clearMeshSelect();
468 
469  // Add point to selection
470  void addSelect(const std::vector<uint>& vlist);
471 
472  // Remove points from selection
473  void removeSelect(const std::vector<uint>& vlist);
474 
475  // Update selection colors
476  void updColor(const std::vector<uint>& vlist);
477 
478  // Apply a single clip plane to the bounding box
479  void bBoxClip(BoundingBox3f& bBox, Point3f p, Point3f n);
480 
481  // Make a bounding box from the clipping planes
482  void bBoxFromClip();
483 
484  // Start pixel editing
485  void pixelEditStart(ClipRegion& clip1, ClipRegion& clip2, ClipRegion& clip3);
486 
487  // Pixel editing operations
488  // p, px, py and pz should be in world coordinates
489  void pixelEdit(float pixelRadius, const Point3f& p, const Point3f& px, const Point3f& py, const Point3f& pz,
490  bool doCut, int currentLabel);
491 
492  // Stop pixel editing
493  void pixelEditStop();
494 
495  bool isMainVisible() const {
496  return stack->main()->isVisible() and mainDataTexId;
497  }
498  bool isWorkVisible() const {
499  return stack->work()->isVisible() and workDataTexId;
500  }
501  bool isVisible() const {
502  return isMainVisible() or isWorkVisible();
503  }
504 
505  HVecUS& currentData()
506  {
507  if(stack->work()->isVisible())
508  return stack->work()->data();
509  return stack->main()->data();
510  }
511  const HVecUS& currentData() const
512  {
513  if(stack->work()->isVisible())
514  return stack->work()->data();
515  return stack->main()->data();
516  }
517  Point3f imageGradientW(Point3d worldpos);
518  Point3f imageGradientI(Point3i ipos);
519  uint imageLevel(Point3d worldpos);
520  Point2i imageMinMax();
521 
522  GLenum interpolation(GLuint texId)
523  {
524  if(texId == workDataTexId)
525  return stack->work()->labels() ? GL_NEAREST : GL_LINEAR;
526  else
527  return stack->main()->labels() ? GL_NEAREST : GL_LINEAR;
528  }
529 
530  GLenum internalFormat(GLuint texId)
531  {
532  if(texId == workDataTexId)
533  return Work16Bit ? GL_ALPHA16 : GL_ALPHA8;
534  else
535  return Main16Bit ? GL_ALPHA16 : GL_ALPHA8;
536  }
537 
538  GLenum swapTextureBytes(GLuint texId)
539  {
540  if(texId == workDataTexId)
541  return stack->work()->labels();
542  else
543  return stack->main()->labels();
544  }
545 
546  // Set stack sizes
547  void updateStackSize();
548 
549  // Change the texture scale of the stack
550  void setTexScale(float s);
551 
552  bool valid() const {
553  return stack->storeSize() > 0 and (mainDataTexId or workDataTexId);
554  }
555 
556  protected:
557  // Update a list of vertex labels
558  void updLabel(int label, std::vector<uint>& vlist);
559 
560  // Add a triangle to the VV mesh when converting from unoriented mesh (triangles must be oriented)
561  bool addTriangle(std::vector<vertex>& vertices, Point3i tri);
562 
563  // Create mesh from triangle and vertex lists
564  void meshFromTriangles(std::vector<vertex>& vertices, std::vector<Point3i>& triangles);
565 
566  // Project signal onto mesh vertices
567  void projSignal(HVecUS& data, vertex v, float mindist, float maxdist);
568 
569  // Load 3D texture data, possibly downsampling.
570  void load3DTexData(const GLuint texId, const Point3u size, const ushort* data);
571 
572  // Get step for texture decimation
573  Point3u getTexStep();
574 
575  public:
576  // Clip texture coordinates
577  float trimTex(const float val) {
578  return (trim(val, 0.0f, 1.0f));
579  }
580 
581  Point2f trimTex(const Point2f& val) {
582  return (Point2f(trimTex(val.x()), trimTex(val.y())));
583  }
584 
585  protected:
586  // Return unique triangles
587  static bool uniqueTri(const vvgraph& S, const vertex& v, const vertex& n, const vertex& m)
588  {
589  if(v.id() <= n.id() or v.id() <= m.id() or n.id() == m.id() or !S.edge(v, n) or !S.edge(v, m) or !S.edge(n, m))
590  return false;
591  else
592  return true;
593  }
594 
595  // Return unique lines
596  static bool uniqueLine(const vvgraph& S, const vertex& v, const vertex& n)
597  {
598  if(v.id() <= n.id() or !S.edge(v, n))
599  return false;
600  else
601  return true;
602  }
603 
604  // Test if quad out of bounds, used for clipping 3D data
605  bool testQuad(float a, float b, float c, float d, float x)
606  {
607  if(a > x and b > x and c > x and d > x)
608  return (true);
609  if(a < -x and b < -x and c < -x and d < -x)
610  return (true);
611  return (false);
612  }
613 
614  // See if point should be drawn
615  // bool pDraw(const vertex &v)
616  // {
617  // // Choose which vertices to draw
618  // if(MeshBorder and !v->margin)
619  // return false;
620  // if(MeshCell and v->label != -1)
621  // return false;
622  // return true;
623  // }
624 
625  // Get point color
626  Point3GLub pColor(const vertex& v)
627  {
628  // Get the color
629  Color3f c;
630  if(v->selected)
631  c = Colors::getColor(MeshSelectColor);
632  else if(v->minb != 0 or v->label < 0)
633  c = Colors::getColor(MeshBorderColor);
634  else
635  c = Colors::getColor(MeshColor);
636 
637  return (Point3GLub(255 * c.x(), 255 * c.y(), 255 * c.z()));
638  }
639 
640  // Get line color, and if it should be drawn
641  bool lDraw(const vertex& a, const vertex& b)
642  {
643  // Choose which line to draw
644  if((mesh->meshView() == Mesh::BORDER_MESH)and !(a->margin and b->margin))
645  return false;
646  if((mesh->meshView() == Mesh::CELL_MESH)and !(a->label == -1 and b->label == -1))
647  return false;
648  return true;
649  }
650 
651  // Compute offset for image data including border
652  size_t offset(uint x, uint y, uint z) {
653  return stack->offset(x, y, z);
654  }
655 
656  size_t offset(Point3i ipos) {
657  return stack->offset(ipos);
658  }
659 
660  // Check if in bounds
661  bool boundsOK(int x, int y, int z)
662  {
663  if(x < 0 or y < 0 or z < 0 or x >= int(stack->size().x()) or y >= int(stack->size().y())
664  or z >= int(stack->size().z()))
665  return (false);
666  else
667  return (true);
668  }
669 
670  public:
672  template <typename T> Point3f imageToWorld(const util::Vector<3, T>& img) const
673  {
674  return stack->imageToWorld<T>(img);
675  }
676 
678  template <typename T> util::Vector<3, T> worldToImage(Point3f wrld) const {
679  return stack->worldToImage<T>(wrld);
680  }
681 
682  Point3f worldToImagef(const Point3f& a) const {
683  return worldToImage<float>(a);
684  }
685  Point3i worldToImagei(const Point3f& a) const {
686  return worldToImage<int>(a);
687  }
688  Point3u worldToImageu(const Point3f& a) const {
689  return worldToImage<uint>(a);
690  }
691 
692  // Map scale slider values
693  int toSliderScale(float s);
694  float fromSliderScale(int i);
695 
696  protected:
697  void updateHistogram(std::vector<double>& hist, const HVecUS& data, std::pair<double, double>& minMaxValues,
698  int max_data = 1 << 16, int size = 512);
699  void invalidateHistogram(std::vector<double>& hist) {
700  hist.clear();
701  }
702 
703  // Clear 3D stack texture
704  void clearData(HVecUS& data)
705  {
706  data.resize(stack->storeSize());
707  memset(&data[0], 0, data.size() * sizeof(ushort));
708  }
709 
710  // Return texture info for a vertex (this version used to update color when drawing on mesh)
711  Point3f texCoord(int label, vertex v);
712 
713  // Return texture info for a vertex (this version used to fill VBOs and respects wall heatmap)
714  Point3f texCoord(int label, vertex v, vertex a, vertex b, vertex c);
715 
716  // Set label on triangle
717  bool setLabel(vertex v1, vertex v2, vertex v3, int label)
718  {
719  bool ok = true;
720  if(v1->label > 0 and v1->label != label)
721  ok = false;
722  if(v2->label > 0 and v2->label != label)
723  ok = false;
724  if(v3->label > 0 and v3->label != label)
725  ok = false;
726 
727  if(ok) {
728  if(v1->label == 0)
729  v1->label = label;
730  if(v2->label == 0)
731  v2->label = label;
732  if(v3->label == 0)
733  v3->label = label;
734  }
735  return (ok);
736  }
737 
738  signals:
739  void changedInterface();
740  // void changeSize(uint x, uint y, uint z, float xstep, float ystep, float zstep);
741  void changeSize(const Point3u& size, const Point3f& step, const Point3f& origin);
742  void stackUnloaded();
743 
744  public slots:
745  // Update the colors of all points in the mesh
746  void updColor();
747 
748  // Slots for controls
749  void MainShowSlot(bool val);
750  void MainBrightSlot(int val);
751  void MainOpacitySlot(int val);
752  void MainLabelsSlot(bool val);
753  void Main16BitSlot(bool val);
754 
755  void WorkShowSlot(bool val);
756  void WorkBrightSlot(int val);
757  void WorkOpacitySlot(int val);
758  void WorkLabelsSlot(bool val);
759  void Work16BitSlot(bool val);
760 
761  void SurfShowSlot(bool val);
762  void SurfBrightSlot(int val);
763  void SurfOpacitySlot(int val);
764  void SurfBlendSlot(bool val);
765  void SurfCullSlot(bool val);
766 
767  void SurfNormalSlot(bool val);
768  void SurfLabelSlot(bool val);
769  void SurfHeatSlot(bool val);
770  void SurfParentSlot(bool val);
771 
772  void SurfSignalSlot(bool val);
773  void SurfTextureSlot(bool val);
774  void SurfImageSlot(bool val);
775 
776  void MeshShowSlot(bool val);
777  void ChangeMeshViewModeSlot(int mode);
778  void MeshLinesSlot(bool val);
779  void MeshPointsSlot(bool val);
780 
781  void CellMapSlot(bool val);
782  void ShowTransSlot(bool val);
783  void ShowScaleSlot(bool val);
784  void ShowBBoxSlot(bool val);
785  void TieScalesSlot(bool val); // ALR
786  void ScaleSlotX(int val);
787  void ScaleSlotY(int val);
788  void ScaleSlotZ(int val);
789 
790  // Slots to change transfer functions
791  void setSurfColorMap(const TransferFunction& fct);
792  void setHeatColorMap(const TransferFunction& fct);
793  void setWorkColorMap(const TransferFunction& fct);
794  void setMainColorMap(const TransferFunction& fct);
795 
796  // Slots to detect changes in transfer fct dialog boxes
797  void updateSurfColorMap(const TransferFunction& fct);
798  void updateHeatColorMap(const TransferFunction& fct);
799  void updateWorkColorMap(const TransferFunction& fct);
800  void updateMainColorMap(const TransferFunction& fct);
801 
802  // Update lines or tris
803  void updateImgData();
804  void postUpdateImgData(bool lines, bool tris);
805 
806  signals:
807  void viewerUpdate();
808  void updateSliderScale();
809  void forceSurfHeat();
810  };
811 
812 }
813 #endif
identity_t id() const
Return the identifier of a vertex.
Definition: Vertex.hpp:291
MeshView
Enumeration of the possible visualisations for the Mesh.
Definition: Mesh.hpp:194
std::map< int, Point3f > IntPoint3fMap
Map of an integer to a 3D point.
Definition: Mesh.hpp:63
const qglviewer::ManipulatedFrame & frame() const
Returns the manipulated frame.
Definition: Stack.hpp:389
const qglviewer::ManipulatedFrame & trans() const
Returns the transformation frame.
Definition: Stack.hpp:403
This file contains the definition of a clipping region.
Misc.
TransferFunction surfFct() const
Return the transfer function used to draw the surface in normal mode.
Definition: Mesh.hpp:710
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:661
qglviewer::ManipulatedFrame & getFrame()
Returns the active frame (i.e.
Definition: Stack.hpp:419
Definition: TransferFunctionDlg.hpp:25
Defines the util::Parms class.
TransferFunction transferFct() const
Retrieve the transfer function used to render the volume.
Definition: Store.hpp:122
mgx_EXPORT bool meshFromTriangles(vvgraph &S, std::vector< vertex > &vertices, std::vector< Point3i > &triangles)
This function creates a graph from a triangle soup.
Class to handle rotatable pair of clipping planes.
Definition: ClipRegion.hpp:38
Definition: Shader.hpp:279
Show only the mesh border.
Definition: Mesh.hpp:196
intptr_t vertex_identity_t
Type of the identifier of a vertex.
Definition: Vertex.hpp:42
This class holds the actual mesh as a VV Graph and all sort of properties for it, including visualiza...
Definition: Mesh.hpp:177
bool blending() const
Return if the surface is rendered blended or not.
Definition: Mesh.hpp:890
Definition: ColorBar.hpp:28
Common definitions and utilities for all geometry algorithms This file is shared by cuda...
util::Vector< 3, T > worldToImage(Point3f wrld) const
Go from world coordinates to image coordinates.
Definition: ImageData.hpp:678
CU_HOST_DEVICE void y(const T &v)
Short access to the second element.
Definition: Vector.hpp:670
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
Point3f imageToWorld(const util::Vector< 3, T > &img) const
Go from image coordinates to world coordinates.
Definition: ImageData.hpp:672
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:115
MeshView meshView() const
Return the current view mode for the mesh.
Definition: Mesh.hpp:968
mgxBase_EXPORT bool subdivideBisect(vvgraph &S, const vertex &v1, const vertex &v2, const vertex &v3, bool selected, std::vector< vertex > *vs=0)
Subdivide triangle by bi-sections.
File containing the definition of a Process.
mgxBase_EXPORT void markMargin(vvgraph &M, vvgraph &S, bool remborders)
Mark the cells and tissue margin vertices.
Definition: CutSurf.hpp:31
The Stack class represent the dimensions of the 3D data, and the frames transformations.
Definition: Stack.hpp:35
float opacity() const
Get the current opacity level of the surface.
Definition: Mesh.hpp:758
std::pair< int, int > IntIntPair
Element in IntIntMap.
Definition: Mesh.hpp:76
QEvent(Type type)
CU_HOST_DEVICE void z(const T &v)
Short access to the third element.
Definition: Vector.hpp:679
const Store * work() const
Access the work store.
Definition: Stack.hpp:103
ColorType
Mesh1 and 2 must have the same order for their colors.
Definition: Colors.hpp:34
Definition: ScaleBar.hpp:31
const Store * main() const
Access the main store.
Definition: Stack.hpp:84
Definition: ImageData.hpp:47
TransferFunction heatFct() const
Return the transfer function used to draw the surface in heat mode.
Definition: Mesh.hpp:734
This files contains the definition of a mesh for the Process API.
bool isSurfaceVisible() const
True if the surface is currently visible to the user.
Definition: Mesh.hpp:795
Class defining a transfer function as linear interpolation between set values.
Definition: TransferFunction.hpp:33
Definition: ImageData.hpp:43
edge_t edge(const vertex_t &src, const vertex_t &tgt)
Returns the edge from src to tgt.
Definition: VVGraph.hpp:1964
Show only the cell borders (i.e. interface between labels)
Definition: Mesh.hpp:197