Chaste  Build::
AbstractActorGenerator.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4  All rights reserved.
5 
6  University of Oxford means the Chancellor, Masters and Scholars of the
7  University of Oxford, having an administrative office at Wellington
8  Square, Oxford OX1 2JD, UK.
9 
10  This file is Abstract of Chaste.
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A AbstractICULAR PURPOSE
26  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34  */
35 
36 #include <boost/filesystem.hpp>
37 #include <boost/lexical_cast.hpp>
38 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the vtk deprecated warning
39 #include <vtkPoints.h>
40 #include <vtkPolyData.h>
41 #include <vtkPolyDataMapper.h>
42 #include <vtkActor.h>
43 #include <vtkProperty.h>
44 #include <vtkUnsignedCharArray.h>
45 #if VTK_MAJOR_VERSION > 5
46  #include <vtkNamedColors.h>
47 #endif
48 #include <vtkSphereSource.h>
49 #include <vtkGlyph3D.h>
50 #include <vtkGlyph2D.h>
51 #include <vtkCubeAxesActor2D.h>
52 #include <vtkImageData.h>
53 #include <vtkGeometryFilter.h>
54 #include <vtkTubeFilter.h>
55 #include <vtkExtractEdges.h>
56 #include <vtkUnstructuredGrid.h>
57 #include <vtkCell.h>
58 #include <vtkPolygon.h>
59 #include <vtkIdList.h>
60 #include <vtkFeatureEdges.h>
61 #include "UblasIncludes.hpp"
62 #include "UblasVectorInclude.hpp"
63 #include "Exception.hpp"
64 #include "BaseUnits.hpp"
65 
66 #include "AbstractActorGenerator.hpp"
67 
68 template<unsigned DIM>
70  : mpColorTransferFunction(vtkSmartPointer<vtkColorTransferFunction>::New()),
71  mLengthScale(BaseUnits::Instance()->GetReferenceLengthScale()),
72  mShowEdges(true),
73  mShowPoints(false),
74  mShowVolume(true),
75  mEdgeColor(zero_vector<double>(3)),
76  mPointColor(unit_vector<double>(3, 2)),
77  mVolumeColor(unit_vector<double>(3, 0)),
78  mViridisColorMap(),
79  mVolumeOpacity(0.6),
80  mPointSize(1.0),
81  mEdgeSize(0.5),
82  mDataLabel()
83 {
84  mPointColor*=255.0;
85  mVolumeColor*=255.0;
86 
87  double viridis_colors[256][3] =
88  { {0.0267004, 0.004874, 0.329415},
89  {0.0268510, 0.009605, 0.335427},
90  {0.0269944, 0.014625, 0.341379},
91  {0.0271305, 0.019942, 0.347269},
92  {0.0272594, 0.025563, 0.353093},
93  {0.0273809, 0.031497, 0.358853},
94  {0.0274952, 0.037752, 0.364543},
95  {0.0276022, 0.044167, 0.370164},
96  {0.0277018, 0.050344, 0.375715},
97  {0.0277941, 0.056324, 0.381191},
98  {0.0278791, 0.062145, 0.386592},
99  {0.0279566, 0.067836, 0.391917},
100  {0.0280267, 0.073417, 0.397163},
101  {0.0280894, 0.078907, 0.402329},
102  {0.0281446, 0.084320, 0.407414},
103  {0.0281924, 0.089666, 0.412415},
104  {0.0282327, 0.094955, 0.417331},
105  {0.0282656, 0.100196, 0.422160},
106  {0.0282910, 0.105393, 0.426902},
107  {0.0283091, 0.110553, 0.431554},
108  {0.0283197, 0.115680, 0.436115},
109  {0.0283229, 0.120777, 0.440584},
110  {0.0283187, 0.125848, 0.444960},
111  {0.0283072, 0.130895, 0.449241},
112  {0.0282884, 0.135920, 0.453427},
113  {0.0282623, 0.140926, 0.457517},
114  {0.0282290, 0.145912, 0.461510},
115  {0.0281887, 0.150881, 0.465405},
116  {0.0281412, 0.155834, 0.469201},
117  {0.0280868, 0.160771, 0.472899},
118  {0.0280255, 0.165693, 0.476498},
119  {0.0279574, 0.170599, 0.479997},
120  {0.0278826, 0.175490, 0.483397},
121  {0.0278012, 0.180367, 0.486697},
122  {0.0277134, 0.185228, 0.489898},
123  {0.0276194, 0.190074, 0.493001},
124  {0.0275191, 0.194905, 0.496005},
125  {0.0274128, 0.199721, 0.498911},
126  {0.0273006, 0.204520, 0.501721},
127  {0.0271828, 0.209303, 0.504434},
128  {0.0270595, 0.214069, 0.507052},
129  {0.0269308, 0.218818, 0.509577},
130  {0.0267968, 0.223549, 0.512008},
131  {0.0266580, 0.228262, 0.514349},
132  {0.0265145, 0.232956, 0.516599},
133  {0.0263663, 0.237631, 0.518762},
134  {0.0262138, 0.242286, 0.520837},
135  {0.0260571, 0.246922, 0.522828},
136  {0.0258965, 0.251537, 0.524736},
137  {0.0257322, 0.256130, 0.526563},
138  {0.0255645, 0.260703, 0.528312},
139  {0.0253935, 0.265254, 0.529983},
140  {0.0252194, 0.269783, 0.531579},
141  {0.0250425, 0.274290, 0.533103},
142  {0.0248629, 0.278775, 0.534556},
143  {0.0246811, 0.283237, 0.535941},
144  {0.0244972, 0.287675, 0.537260},
145  {0.0243113, 0.292092, 0.538516},
146  {0.0241237, 0.296485, 0.539709},
147  {0.0239346, 0.300855, 0.540844},
148  {0.0237441, 0.305202, 0.541921},
149  {0.0235526, 0.309527, 0.542944},
150  {0.0233603, 0.313828, 0.543914},
151  {0.0231674, 0.318106, 0.544834},
152  {0.0229739, 0.322361, 0.545706},
153  {0.0227802, 0.326594, 0.546532},
154  {0.0225863, 0.330805, 0.547314},
155  {0.0223925, 0.334994, 0.548053},
156  {0.0221989, 0.339161, 0.548752},
157  {0.0220057, 0.343307, 0.549413},
158  {0.0218130, 0.347432, 0.550038},
159  {0.0216210, 0.351535, 0.550627},
160  {0.0214298, 0.355619, 0.551184},
161  {0.0212395, 0.359683, 0.551710},
162  {0.0210503, 0.363727, 0.552206},
163  {0.0208623, 0.367752, 0.552675},
164  {0.0206756, 0.371758, 0.553117},
165  {0.0204903, 0.375746, 0.553533},
166  {0.0203063, 0.379716, 0.553925},
167  {0.0201239, 0.383670, 0.554294},
168  {0.0199430, 0.387607, 0.554642},
169  {0.0197636, 0.391528, 0.554969},
170  {0.0195860, 0.395433, 0.555276},
171  {0.0194100, 0.399323, 0.555565},
172  {0.0192357, 0.403199, 0.555836},
173  {0.0190631, 0.407061, 0.556089},
174  {0.0188923, 0.410910, 0.556326},
175  {0.0187231, 0.414746, 0.556547},
176  {0.0185556, 0.418570, 0.556753},
177  {0.0183898, 0.422383, 0.556944},
178  {0.0182256, 0.426184, 0.557120},
179  {0.0180629, 0.429975, 0.557282},
180  {0.0179019, 0.433756, 0.557430},
181  {0.0177423, 0.437527, 0.557565},
182  {0.0175841, 0.441290, 0.557685},
183  {0.0174274, 0.445044, 0.557792},
184  {0.0172719, 0.448791, 0.557885},
185  {0.0171176, 0.452530, 0.557965},
186  {0.0169646, 0.456262, 0.558030},
187  {0.0168126, 0.459988, 0.558082},
188  {0.0166617, 0.463708, 0.558119},
189  {0.0165117, 0.467423, 0.558141},
190  {0.0163625, 0.471133, 0.558148},
191  {0.0162142, 0.474838, 0.558140},
192  {0.0160665, 0.478540, 0.558115},
193  {0.0159194, 0.482237, 0.558073},
194  {0.0157729, 0.485932, 0.558013},
195  {0.0156270, 0.489624, 0.557936},
196  {0.0154815, 0.493313, 0.557840},
197  {0.0153364, 0.497000, 0.557724},
198  {0.0151918, 0.500685, 0.557587},
199  {0.0150476, 0.504369, 0.557430},
200  {0.0149039, 0.508051, 0.557250},
201  {0.0147607, 0.511733, 0.557049},
202  {0.0146180, 0.515413, 0.556823},
203  {0.0144759, 0.519093, 0.556572},
204  {0.0143343, 0.522773, 0.556295},
205  {0.0141935, 0.526453, 0.555991},
206  {0.0140536, 0.530132, 0.555659},
207  {0.0139147, 0.533812, 0.555298},
208  {0.0137770, 0.537492, 0.554906},
209  {0.0136408, 0.541173, 0.554483},
210  {0.0135066, 0.544853, 0.554029},
211  {0.0133743, 0.548535, 0.553541},
212  {0.0132444, 0.552216, 0.553018},
213  {0.0131172, 0.555899, 0.552459},
214  {0.0129933, 0.559582, 0.551864},
215  {0.0128729, 0.563265, 0.551229},
216  {0.0127568, 0.566949, 0.550556},
217  {0.0126453, 0.570633, 0.549841},
218  {0.0125394, 0.574318, 0.549086},
219  {0.0124395, 0.578002, 0.548287},
220  {0.0123463, 0.581687, 0.547445},
221  {0.0122606, 0.585371, 0.546557},
222  {0.0121831, 0.589055, 0.545623},
223  {0.0121148, 0.592739, 0.544641},
224  {0.0120565, 0.596422, 0.543611},
225  {0.0120092, 0.600104, 0.542530},
226  {0.0119738, 0.603785, 0.541400},
227  {0.0119512, 0.607464, 0.540218},
228  {0.0119423, 0.611141, 0.538982},
229  {0.0119483, 0.614817, 0.537692},
230  {0.0119699, 0.618490, 0.536347},
231  {0.0120081, 0.622161, 0.534946},
232  {0.0120638, 0.625828, 0.533488},
233  {0.0121380, 0.629492, 0.531973},
234  {0.0122312, 0.633153, 0.530398},
235  {0.0123444, 0.636809, 0.528763},
236  {0.0124780, 0.640461, 0.527068},
237  {0.0126326, 0.644107, 0.525311},
238  {0.0128087, 0.647749, 0.523491},
239  {0.0130067, 0.651384, 0.521608},
240  {0.0132268, 0.655014, 0.519661},
241  {0.0134692, 0.658636, 0.517649},
242  {0.0137339, 0.662252, 0.515571},
243  {0.0140210, 0.665859, 0.513427},
244  {0.0143303, 0.669459, 0.511215},
245  {0.0146616, 0.673050, 0.508936},
246  {0.0150148, 0.676631, 0.506589},
247  {0.0153894, 0.680203, 0.504172},
248  {0.0157851, 0.683765, 0.501686},
249  {0.0162016, 0.687316, 0.499129},
250  {0.0166383, 0.690856, 0.496502},
251  {0.0170948, 0.694384, 0.493803},
252  {0.0175707, 0.697900, 0.491033},
253  {0.0180653, 0.701402, 0.488189},
254  {0.0185783, 0.704891, 0.485273},
255  {0.0191090, 0.708366, 0.482284},
256  {0.0196571, 0.711827, 0.479221},
257  {0.0202219, 0.715272, 0.476084},
258  {0.0208030, 0.718701, 0.472873},
259  {0.0214000, 0.722114, 0.469588},
260  {0.0220124, 0.725509, 0.466226},
261  {0.0226397, 0.728888, 0.462789},
262  {0.0232815, 0.732247, 0.459277},
263  {0.0239374, 0.735588, 0.455688},
264  {0.0246070, 0.738910, 0.452024},
265  {0.0252899, 0.742211, 0.448284},
266  {0.0259857, 0.745492, 0.444467},
267  {0.0266941, 0.748751, 0.440573},
268  {0.0274149, 0.751988, 0.436601},
269  {0.0281477, 0.755203, 0.432552},
270  {0.0288921, 0.758394, 0.428426},
271  {0.0296479, 0.761561, 0.424223},
272  {0.0304148, 0.764704, 0.419943},
273  {0.0311925, 0.767822, 0.415586},
274  {0.0319809, 0.770914, 0.411152},
275  {0.0327796, 0.773980, 0.406640},
276  {0.0335885, 0.777018, 0.402049},
277  {0.0344074, 0.780029, 0.397381},
278  {0.0352360, 0.783011, 0.392636},
279  {0.0360741, 0.785964, 0.387814},
280  {0.0369214, 0.788888, 0.382914},
281  {0.0377779, 0.791781, 0.377939},
282  {0.0386433, 0.794644, 0.372886},
283  {0.0395174, 0.797475, 0.367757},
284  {0.0404001, 0.800275, 0.362552},
285  {0.0412913, 0.803041, 0.357269},
286  {0.0421908, 0.805774, 0.351910},
287  {0.0430983, 0.808473, 0.346476},
288  {0.0440137, 0.811138, 0.340967},
289  {0.0449368, 0.813768, 0.335384},
290  {0.0458674, 0.816363, 0.329727},
291  {0.0468053, 0.818921, 0.323998},
292  {0.0477504, 0.821444, 0.318195},
293  {0.0487026, 0.823929, 0.312321},
294  {0.0496615, 0.826376, 0.306377},
295  {0.0506271, 0.828786, 0.300362},
296  {0.0515992, 0.831158, 0.294279},
297  {0.0525776, 0.833491, 0.288127},
298  {0.0535621, 0.835785, 0.281908},
299  {0.0545524, 0.838039, 0.275626},
300  {0.0555484, 0.840254, 0.269281},
301  {0.0565498, 0.842430, 0.262877},
302  {0.0575563, 0.844566, 0.256415},
303  {0.0585678, 0.846661, 0.249897},
304  {0.0595839, 0.848717, 0.243329},
305  {0.0606045, 0.850733, 0.236712},
306  {0.0616293, 0.852709, 0.230052},
307  {0.0626579, 0.854645, 0.223353},
308  {0.0636902, 0.856542, 0.216620},
309  {0.0647257, 0.858400, 0.209861},
310  {0.0657642, 0.860219, 0.203082},
311  {0.0668054, 0.861999, 0.196293},
312  {0.0678489, 0.863742, 0.189503},
313  {0.0688944, 0.865448, 0.182725},
314  {0.0699415, 0.867117, 0.175971},
315  {0.0709898, 0.868751, 0.169257},
316  {0.0720391, 0.870350, 0.162603},
317  {0.0730889, 0.871916, 0.156029},
318  {0.0741388, 0.873449, 0.149561},
319  {0.0751884, 0.874951, 0.143228},
320  {0.0762373, 0.876424, 0.137064},
321  {0.0772852, 0.877868, 0.131109},
322  {0.0783315, 0.879285, 0.125405},
323  {0.0793760, 0.880678, 0.120005},
324  {0.0804182, 0.882046, 0.114965},
325  {0.0814576, 0.883393, 0.110347},
326  {0.0824940, 0.884720, 0.106217},
327  {0.0835270, 0.886029, 0.102646},
328  {0.0845561, 0.887322, 0.099702},
329  {0.0855810, 0.888601, 0.097452},
330  {0.0866013, 0.889868, 0.095953},
331  {0.0876168, 0.891125, 0.095250},
332  {0.0886271, 0.892374, 0.095374},
333  {0.0896320, 0.893616, 0.096335},
334  {0.0906311, 0.894855, 0.098125},
335  {0.0916242, 0.896091, 0.100717},
336  {0.0926106, 0.897330, 0.104071},
337  {0.0935904, 0.898570, 0.108131},
338  {0.0945636, 0.899815, 0.112838},
339  {0.0955300, 0.901065, 0.118128},
340  {0.0964894, 0.902323, 0.123941},
341  {0.0974417, 0.903590, 0.130215},
342  {0.0983868, 0.904867, 0.136897},
343  {0.0993248, 0.906157, 0.143936}};
344 
345  for(unsigned idx=0; idx<256;idx++)
346  {
347  mpColorTransferFunction->AddRGBPoint(double(idx)/255.0,
348  viridis_colors[idx][0],
349  viridis_colors[idx][1],
350  viridis_colors[idx][2]);
351  }
352 }
353 
354 template<unsigned DIM>
356 {
357 
358 }
359 
360 template<unsigned DIM>
362 {
363  mShowEdges = show;
364 }
365 
366 template<unsigned DIM>
368 {
369  mShowPoints = show;
370 }
371 
372 template<unsigned DIM>
374 {
375  mPointSize = size;
376 }
377 
378 template<unsigned DIM>
380 {
381  mEdgeSize = size;
382 }
383 
384 template<unsigned DIM>
386 {
387  mShowVolume = show;
388 }
389 
390 template<unsigned DIM>
391 void AbstractActorGenerator<DIM>::SetEdgeColor(const c_vector<double, 3>& rColor)
392 {
393  mEdgeColor = rColor;
394 }
395 
396 template<unsigned DIM>
397 void AbstractActorGenerator<DIM>::SetPointColor(const c_vector<double, 3>& rColor)
398 {
399  mPointColor = rColor;
400 }
401 
402 template<unsigned DIM>
403 void AbstractActorGenerator<DIM>::SetVolumeColor(const c_vector<double, 3>& rColor)
404 {
405  mVolumeColor = rColor;
406 }
407 
408 template<unsigned DIM>
410 {
411  mVolumeOpacity = opacity;
412 }
413 
414 template<unsigned DIM>
415 void AbstractActorGenerator<DIM>::SetDataLabel(const std::string& rLabel)
416 {
417  mDataLabel = rLabel;
418 }
419 
420 
421 template class AbstractActorGenerator<2>;
422 template class AbstractActorGenerator<3>;
c_vector< double, 3 > mEdgeColor
void SetVolumeColor(const c_vector< double, 3 > &rColor)
void SetPointColor(const c_vector< double, 3 > &rColor)
c_vector< double, 3 > mPointColor
void SetVolumeOpacity(double opacity)
vtkSmartPointer< vtkColorTransferFunction > mpColorTransferFunction
void SetEdgeColor(const c_vector< double, 3 > &rColor)
c_vector< double, 3 > mVolumeColor