AGX Dynamics  2.35.0.1
PovExporter.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXIO_POV_EXPORTER_H
18 #define AGXIO_POV_EXPORTER_H
19 
20 #include <agx/config.h>
21 #include <agx/agxPhysics_export.h>
22 #include <stdexcept>
23 #include <agx/AffineMatrix4x4.h>
24 #include <agx/RigidBody.h>
25 #include <agxCollide/Geometry.h>
26 #include <agx/Constraint.h>
27 #include <agxSDK/Assembly.h>
28 #include <sstream>
29 namespace agxSDK
30 {
31  class Simulation;
32 }
33 
34 namespace agx {
35  class PropertyContainer;
36  class Material;
37  class ContactMaterial;
38 }
39 
40 namespace agxCollide {
41  class Shape;
42 }
43 
44 namespace agxIO
45 {
50  {
51  public:
53 
65  bool write( const agx::String& filename, agxSDK::Simulation *simulation,
66  agx::Vec3 from, agx::Vec3 at,
67  agx::Vec3 up, double fovy, double aspectRatio );
68 
80  bool write( std::ostream& outStream, agxSDK::Simulation *simulation,
81  agx::Vec3 from, agx::Vec3 at,
82  agx::Vec3 up, double fovy, double aspectRatio );
83 
85 
86  static void setFocalSettings( agx::Real distance, agx::Real aperture, int blur_samples, agx::Real variance );
87  static void setEnableFocalBlur( bool enable );
88 
89  protected:
90 
93  {
95  out.resize(in.size());
96 
97  for(size_t i=0; i < in.size(); i++)
98  {
99  if (isalnum(static_cast<unsigned char>(in[i])))
100  out[i] = in[i];
101  else
102  out[i] = '_';
103  }
104  return "pov_"+out;
105  }
106 
107 
109 // bool exportConstraints();
111  bool exportAssembly( agxSDK::Assembly *assembly );
112  bool exportGeometries( const agx::String& parentMaterial );
113  bool exportShape( const agx::AffineMatrix4x4& t, const agxCollide::Shape *shape, const agx::String& parentMaterial );
114  bool exportGeometry( agxCollide::Geometry *geometry, const agx::String& parentMaterial);
116 
120 
122 #ifdef GET_NAME
123 #undef GET_NAME
124 #endif
125 #define GET_NAME(TYPE, NAME) \
126  typedef agx::HashTable<const TYPE *, agx::String> NameTable ##NAME; \
127  typedef agx::HashSet<agx::String> UniqueNameTable ##NAME; \
128  NameTable ##NAME m_exportedName ##NAME; \
129  UniqueNameTable ##NAME m_uniqueNames ##NAME; \
130  \
131  inline agx::String getName( const TYPE *item ) \
132  { \
133  agx::String name = item->getName(); \
134  NameTable ##NAME::const_iterator nameIt = m_exportedName ##NAME.find(item); \
135  if (nameIt != m_exportedName ##NAME.end()) \
136  return cleanupString(nameIt->second); /* use the associated name */ \
137  if (name.empty()) { \
138  std::stringstream str; \
139  str << #NAME << "_" << item->getIndex(); \
140  name = str.str(); \
141  m_exportedName ##NAME.insert(item, name); \
142  m_uniqueNames ##NAME.insert(name); \
143  return cleanupString(name); \
144  } \
145  else { /* Not empty, but is it unique? */ \
146  UniqueNameTable ##NAME::const_iterator it = m_uniqueNames ##NAME.find(name); \
147  if (it == m_uniqueNames ##NAME.end() ) \
148  { \
149  m_uniqueNames ##NAME.insert(name); \
150  m_exportedName ##NAME.insert(item, name); \
151  return cleanupString(name); \
152  } \
153  \
154  std::stringstream str; \
155  str << name << "_" << item->getIndex(); /* Create a new unique name and use that for this item */ \
156  name = str.str(); \
157  m_exportedName ##NAME.insert(item, name); \
158  m_uniqueNames ##NAME.insert(name); \
159  } \
160  return cleanupString(name); \
161  }
162 
163  GET_NAME(agx::RigidBody, Bodies)
164  GET_NAME(agxCollide::Geometry, Geometries)
165  GET_NAME(agxSDK::Assembly, Assemblies)
166 
167  #undef GET_NAME
168 
172 
174 
175  std::ostream *m_outStream;
176 
181  static int m_blurSamples;
182  static bool m_focalBlurEnable;
183  };
184 
185 }
186 #endif
#define GET_NAME(TYPE, NAME)
Definition: PovExporter.h:125
#define AGXPHYSICS_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Base class for a shape.
Definition: Shape.h:54
Class for exporting a simulation into AGX .pov format.
Definition: PovExporter.h:50
static void setFocalSettings(agx::Real distance, agx::Real aperture, int blur_samples, agx::Real variance)
GeometryPtrHashSet m_geometryHasMaterial
Definition: PovExporter.h:121
std::ostream * m_outStream
Definition: PovExporter.h:175
static agx::Real m_aperture
Definition: PovExporter.h:179
bool exportRigidBody(agx::RigidBody *body)
static agx::Real m_variance
Definition: PovExporter.h:180
static int m_blurSamples
Definition: PovExporter.h:181
agxSDK::Simulation * m_simulation
Definition: PovExporter.h:173
static void setEnableFocalBlur(bool enable)
AssemblyPtrHashSet m_exportedAssemblies
Definition: PovExporter.h:169
agx::HashSet< agxSDK::Assembly * > AssemblyPtrHashSet
Definition: PovExporter.h:119
agx::HashSet< agxCollide::Geometry * > GeometryPtrHashSet
Definition: PovExporter.h:118
static bool m_focalBlurEnable
Definition: PovExporter.h:182
agx::HashSet< agx::RigidBody * > RigidBodyPtrHashSet
Definition: PovExporter.h:117
RigidBodyPtrHashSet m_exportedBodies
Definition: PovExporter.h:170
bool exportShape(const agx::AffineMatrix4x4 &t, const agxCollide::Shape *shape, const agx::String &parentMaterial)
bool exportGeometries(const agx::String &parentMaterial)
bool write(const agx::String &filename, agxSDK::Simulation *simulation, agx::Vec3 from, agx::Vec3 at, agx::Vec3 up, double fovy, double aspectRatio)
Write a simulation into the Pov-ray file format for rendering.
static agx::Real m_focalDistance
Definition: PovExporter.h:178
agx::String cleanupString(const agx::String &in)
Translate any non-alphanumeric letters into '_'.
Definition: PovExporter.h:92
bool exportAssembly(agxSDK::Assembly *assembly)
bool write(std::ostream &outStream, agxSDK::Simulation *simulation, agx::Vec3 from, agx::Vec3 at, agx::Vec3 up, double fovy, double aspectRatio)
Write a simulation in .pov format to a stream.
GeometryPtrHashSet m_exportedGeometries
Definition: PovExporter.h:171
bool exportGeometry(agxCollide::Geometry *geometry, const agx::String &parentMaterial)
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:67
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxIO namespace contains classes for reading, writing and finding files.
Definition: Material.h:42
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
double Real
Definition: Real.h:42