TexGen
TexGenRenderer.h
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#pragma once
21
22#include "../Core/TexGen.h"
23namespace TexGen
24{
25 struct PROP_INFO { virtual ~PROP_INFO() {} };
26
27 struct PROP_YARN_INFO : public PROP_INFO
28 {
30 int iYarn;
31 };
32
33 struct PROP_NODE_INFO : public PROP_INFO
34 {
36 int iYarn;
37 int iNode;
38 };
39
40 struct PROP_IMAGE_INFO : public PROP_INFO
41 {
43 };
44
46 inline bool operator < (const PROP_YARN_INFO &left, const PROP_YARN_INFO &right)
47 {
48 if (left.TextileName != right.TextileName)
49 return left.TextileName < right.TextileName;
50 else if (left.iYarn != right.iYarn)
51 return left.iYarn < right.iYarn;
52 else
53 return false;
54 }
55
57 inline bool operator < (const PROP_NODE_INFO &left, const PROP_NODE_INFO &right)
58 {
59 if (left.TextileName != right.TextileName)
60 return left.TextileName < right.TextileName;
61 else if (left.iYarn != right.iYarn)
62 return left.iYarn < right.iYarn;
63 else if (left.iNode != right.iNode)
64 return left.iNode < right.iNode;
65 else
66 return false;
67 }
68
69 class CTextile; // This makes sure that swig knows CTextile is part of the TexGen namespace...
71
77 {
78 public:
79 CTexGenRenderer(vtkRenderWindowInteractor *pRenderWindowInteractor = NULL);
80 ~CTexGenRenderer(void);
81
83 {
95 };
96
98 {
103 };
104
106
110 void RenderTextile(string TextileName = "", double dOpacity = 1);
111
113
117 void RenderTextile(CTextile &Textile, double dOpacity = 1);
118
120 vtkProp* RenderYarn(CYarn &Yarn, const CDomain *pDomain = NULL, COLOR Color = COLOR(1, 1, 1), double dOpacity = 1);
121
123
126 void RenderMesh(string TextileName = "");
127
129
133 void RenderMesh(CTextile &Textile);
134
136 vtkProp* RenderYarnMesh(CYarn &Yarn, const CDomain *pDomain = NULL, COLOR Color = COLOR(1, 1, 1));
137
139 void RenderDomain(string TextileName = "", COLOR Color = COLOR(1, 1, 1), double dOpacity = 0.5);
140
142 void RenderDomain(const CDomain &Domain, COLOR Color = COLOR(1, 1, 1), double dOpacity = 0.5);
143
145 void RenderDomainAxes(string TextileName = "");
146
148 void RenderDomainAxes(const CDomain &Domain);
149
151 void RenderNodes(string TextileName = "");
152
154 void RenderNodes(CTextile &Textile);
155
157 void RenderNodes(CTextile &Textile, int iYarn);
158
160 void RenderPaths(string TextileName = "");
161
163 void RenderPaths(CTextile &Textile);
164
166 void RenderPath(CTextile &Textile, int iYarn);
167
170 void RenderInterference(string TextileName = "", bool bDepth = false );
171
174 void RenderInterference(CTextile &Textile, bool bDepth = false);
175
178 void RenderGrid(string TextileName = "", int iResX = 20, int iResY = 20, int iResZ = 20, double dLengthModifier = 1);
179
182 void RenderGrid(CTextile &Textile, int iResX = 20, int iResY = 20, int iResZ = 20, double dLengthModifier = 1);
183
185 //bool RenderImage(string FileName, double dMaxDim = 1, XYZ Orientation = XYZ());
186
188 void SetBackgroundColor(COLOR Color);
189
191 void RenderAxes();
192
194 void ClearScene();
195
197 void RemoveProps(PROP_TYPE Type);
198
200 void SetPropsColor(PROP_TYPE Type, COLOR Color);
201
203 int GetNumProps(PROP_TYPE Type) const;
204
206 vector<vtkProp*> GetProps(PROP_TYPE Type);
207
209 vector<vtkProp*> GetProps(set<PROP_TYPE> Types);
210
212 const PROP_YARN_INFO *GetYarnPropInfo(vtkProp* pProp) const;
213
215 const PROP_NODE_INFO *GetNodePropInfo(vtkProp* pProp) const;
216
218 const PROP_IMAGE_INFO *GetImagePropInfo(vtkProp* pProp) const;
219
221 vector<vtkProp*> GetProps(PROP_INFO* pInfo, bool bIgnoreTextileName = false);
222
224 vector<vtkProp*> GetNodeProps(PROP_YARN_INFO Info, bool bIgnoreTextileName = false);
225
227 void RefreshYarn(PROP_YARN_INFO YarnInfo);
228
230 void RefreshTextile(string TextileName);
231
233 void ResetCamera(XYZ LookDirection = XYZ());
234
236 void RefreshView();
237
239
247 void Start(bool bTakeControl = true, int iWidth = 800, int iHeight = 600, bool bFullScreen = false);
248
250
257 void TakeScreenShot(string FileName, int iMagnification = 1);
258
260 void SetParallelProjection(bool bParallelProjection);
261
263 vtkRenderer * GetRenderer() { return m_pRenderer; }
264
266 vtkRenderWindowInteractor * GetInteractor() { return m_pRenderWindowInteractor; }
267
269 void SetCallback(void (*pCallback)());
270
272 void SetXRay(bool bXRay);
273
275 void SetTrimToDomain(bool bTrim);
276
278 void SetYarnColor(int iYarn, COLOR Color);
279
281 static void ApplyColor(vtkActor *pActor, COLOR Color);
282
284 void ApplyDefaultColor(vtkActor *pActor);
285
287
293 bool SaveTextileToVTK(string FileName, string TextileName = "", int iExportFlags = EXPORT_NODES | EXPORT_PATH | EXPORT_SURFACE | EXPORT_DOMAIN);
294
296 bool SaveMeshToVTK(string FileName, const CMesh &Mesh);
297
299
306 void BeginBatch();
307
309
316 void EndBatch();
317
318 // Convenience functions
323 void RemoveAxes() { m_pOrientationMarkerWidget->SetEnabled(0); RefreshView();/*RemoveProps(PROP_AXES);*/ }
329 vtkPolyData *GetPolyData(const CMesh &Mesh);
330 bool GetXRay() const { return m_bXRay; }
331 bool GetTrimToDomain() const { return m_bTrimToDomain; }
333 bool GetParallelProjection() const;
334
335
336 protected:
338
342 void UpdateAxesColor();
343
345
350
352 void AddProp(PROP_TYPE Type, vtkProp *pProp);
353
354 // Remove an actor from the scene
355 void RemoveProp(vtkProp *pProp);
356
358 int GetUniqueImageID();
359
361 vtkActor *ConvertToActor(vtkAlgorithm *pAlgorithm);
363 vtkActor *ConvertToActor(vtkPolyData *pPolyData);
364 vtkAlgorithm *CalculateNormals(vtkPolyData *pInput);
365
367// void RenderDirection(XYZ Position, XYZ Direction, PROP_TYPE Type, double dScale = 1, double adColor[3] = COLOR_WHITE, bool bRefresh = true);
368
369 multimap<PROP_TYPE, vtkProp*> m_Props;
370 map<vtkProp*, PROP_YARN_INFO> m_YarnProps;
371 map<vtkProp*, PROP_NODE_INFO> m_NodeProps;
372 map<vtkProp*, PROP_IMAGE_INFO> m_ImageProps;
373
374 vtkRenderer *m_pRenderer;
375 vtkRenderWindow *m_pRenderWindow;
376 vtkRenderWindowInteractor *m_pRenderWindowInteractor;
377 vtkOrientationMarkerWidget *m_pOrientationMarkerWidget;
378
379 void (*m_pCallback)();
380
384 };
385
386}; // namespace TexGen
#define NULL
Definition: ShinyConfig.h:50
Abstract base class representing the domain in which a textile cell may lie.
Definition: Domain.h:34
Defines the nodes and elements of a surface or volume mesh.
Definition: Mesh.h:58
Used for rendering stuff using VTK http://www.vtk.org/.
void UpdateAxesColor()
Updates the axes color based on the background color.
void RefreshView()
Re-render the scene to take into account updates to it.
void TakeScreenShot(string FileName, int iMagnification=1)
Saves the current view as a PNG image on the hard disk.
void SetTrimToDomain(bool bTrim)
Render yarns as transparent.
vector< vtkProp * > GetProps(PROP_TYPE Type)
Get the vtkProps of a given type.
map< vtkProp *, PROP_YARN_INFO > m_YarnProps
void RenderDomainAxes(string TextileName="")
Render the dimensions of the domain.
void RenderPaths(string TextileName="")
Render the paths of each yarn in a textile.
void RenderAxes()
Render axes at the bottom left of the window.
void RenderPath(CTextile &Textile, int iYarn)
Render the path of a yarn in a textile.
void SetYarnColor(int iYarn, COLOR Color)
Set the colors of the yarns.
bool GetTrimToDomain() const
int GetNumProps(PROP_TYPE Type) const
Find out how many actors of given type exist.
vtkProp * RenderYarnMesh(CYarn &Yarn, const CDomain *pDomain=NULL, COLOR Color=COLOR(1, 1, 1))
Render a single yarn mesh with given color.
vtkPolyData * GetPolyData(const CMesh &Mesh)
vtkProp * RenderYarn(CYarn &Yarn, const CDomain *pDomain=NULL, COLOR Color=COLOR(1, 1, 1), double dOpacity=1)
Render a single yarn with given color.
int GetUniqueImageID()
Return a unique ID assigned to an image.
map< vtkProp *, PROP_IMAGE_INFO > m_ImageProps
const PROP_NODE_INFO * GetNodePropInfo(vtkProp *pProp) const
Get information about the node prop.
void RefreshYarn(PROP_YARN_INFO YarnInfo)
Re-render the yarn after it has been updated.
multimap< PROP_TYPE, vtkProp * > m_Props
This function will render a direction at a given point.
void SetXRay(bool bXRay)
Render yarns as transparent.
void SetPropsColor(PROP_TYPE Type, COLOR Color)
Remove all actors of given type.
void SetCallback(void(*pCallback)())
Set the callback function when an actor is added or deleted.
void AddProp(PROP_TYPE Type, vtkProp *pProp)
Add an actor to the scene.
void RenderGrid(string TextileName="", int iResX=20, int iResY=20, int iResZ=20, double dLengthModifier=1)
vtkAlgorithm * CalculateNormals(vtkPolyData *pInput)
void RefreshTextile(string TextileName)
Re-render the textile after it has been updated.
vector< vtkProp * > GetNodeProps(PROP_YARN_INFO Info, bool bIgnoreTextileName=false)
Get the vtkProps associated with the given object.
void RenderInterference(string TextileName="", bool bDepth=false)
void ClearScene()
Remove all objects being rendered.
bool SaveTextileToVTK(string FileName, string TextileName="", int iExportFlags=EXPORT_NODES|EXPORT_PATH|EXPORT_SURFACE|EXPORT_DOMAIN)
Save textile data to VTK file format.
vtkRenderWindowInteractor * GetInteractor()
Get the renderer object.
void EndBatch()
Decrement batch count.
void RenderNodes(string TextileName="")
Render all the master nodes of each yarn in a textile.
void RenderMesh(string TextileName="")
Create the volume mesh and add it to the scene to be rendered.
bool GetParallelProjection() const
Determine if parallel projection or perspective projection is switched on.
map< vtkProp *, PROP_NODE_INFO > m_NodeProps
vtkRenderer * GetRenderer()
Get the renderer object.
vtkActor * ConvertToActor(vtkAlgorithm *pAlgorithm)
This function will convert a vtkAlgorithm class into an vtkActor for rendering.
void RemoveProps(PROP_TYPE Type)
Remove all actors of given type.
vtkRenderWindowInteractor * m_pRenderWindowInteractor
vtkOrientationMarkerWidget * m_pOrientationMarkerWidget
void SetParallelProjection(bool bParallelProjection)
Switch between parallel projection and perspective projection.
void BeginBatch()
Increment batch count.
void Start(bool bTakeControl=true, int iWidth=800, int iHeight=600, bool bFullScreen=false)
Create a new render window and render to it (optionally taking control of the thread)
void RenderTextile(string TextileName="", double dOpacity=1)
Create the mesh and add it to the scene to be rendered.
void ApplyDefaultColor(vtkActor *pActor)
Apply the default material color based on the yarn index.
const PROP_IMAGE_INFO * GetImagePropInfo(vtkProp *pProp) const
Get information about the image prop.
void RemoveProp(vtkProp *pProp)
static void ApplyColor(vtkActor *pActor, COLOR Color)
Apply the material properties.
CTexGenRenderer(vtkRenderWindowInteractor *pRenderWindowInteractor=NULL)
void SetBackgroundColor(COLOR Color)
Render an image.
bool SaveMeshToVTK(string FileName, const CMesh &Mesh)
Save a Mesh to VTK file format.
COLOR GetBestAnnotationColor()
Gets the best text color based on the color of the background.
const PROP_YARN_INFO * GetYarnPropInfo(vtkProp *pProp) const
Get information about the surface prop.
void RenderDomain(string TextileName="", COLOR Color=COLOR(1, 1, 1), double dOpacity=0.5)
Render the domain.
void ResetCamera(XYZ LookDirection=XYZ())
Reset the camera so as to see all objects that are rendered.
vtkRenderWindow * m_pRenderWindow
Represents a textile cell containing yarns.
Definition: Textile.h:39
Represents a yarn consisting of master nodes, section and interpolation function.
Definition: Yarn.h:49
Namespace containing a series of customised math operations not found in the standard c++ library.
bool operator<(const PROP_YARN_INFO &left, const PROP_YARN_INFO &right)
Used for sorting algorithms.
virtual ~PROP_INFO()
Struct for representing points in 3D space.
Definition: mymath.h:56