AGX Dynamics  2.38.0.2
PovExporter.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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:
52  PovExporter();
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 
84  ~PovExporter();
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 
108  bool exportRigidBodies();
109 // bool exportConstraints();
110  bool exportAssemblies();
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);
115  bool exportRigidBody( agx::RigidBody *body);
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
agxPhysics_export.h
agx::Real
double Real
Definition: Real.h:42
agxIO::PovExporter::m_focalBlurEnable
static bool m_focalBlurEnable
Definition: PovExporter.h:182
agxIO::PovExporter::m_focalDistance
static agx::Real m_focalDistance
Definition: PovExporter.h:178
agxIO::PovExporter::m_exportedBodies
RigidBodyPtrHashSet m_exportedBodies
Definition: PovExporter.h:170
agxStream::out
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.
Definition: OutputArchive.h:412
agxIO::PovExporter::GeometryPtrHashSet
agx::HashSet< agxCollide::Geometry * > GeometryPtrHashSet
Definition: PovExporter.h:118
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
agxIO::PovExporter::m_exportedAssemblies
AssemblyPtrHashSet m_exportedAssemblies
Definition: PovExporter.h:169
GET_NAME
#define GET_NAME(TYPE, NAME)
Definition: PovExporter.h:125
Constraint.h
Geometry.h
agx::AffineMatrix4x4T< Real >
Assembly.h
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxStream::in
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:399
AffineMatrix4x4.h
agxSDK::Assembly
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:67
agxIO::PovExporter::m_blurSamples
static int m_blurSamples
Definition: PovExporter.h:181
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agxCollide::Shape
Base class for a shape.
Definition: Shape.h:53
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:91
agxIO::PovExporter::AssemblyPtrHashSet
agx::HashSet< agxSDK::Assembly * > AssemblyPtrHashSet
Definition: PovExporter.h:119
agxStream::write
bool AGXPHYSICS_EXPORT write(const std::string &filename, const agxStream::Serializable *data)
Write a Serializable object to a file.
agx::HashSet< agx::RigidBody * >
agxIO::PovExporter::m_geometryHasMaterial
GeometryPtrHashSet m_geometryHasMaterial
Definition: PovExporter.h:121
RigidBody.h
agxIO::PovExporter
Class for exporting a simulation into AGX .pov format.
Definition: PovExporter.h:49
agxIO::PovExporter::RigidBodyPtrHashSet
agx::HashSet< agx::RigidBody * > RigidBodyPtrHashSet
Definition: PovExporter.h:117
agxIO::PovExporter::m_declareStarted
bool m_declareStarted
Definition: PovExporter.h:177
agxCollide
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Definition: ContactForceFilterParticipant.h:22
agxIO::PovExporter::m_exportedGeometries
GeometryPtrHashSet m_exportedGeometries
Definition: PovExporter.h:171
agxIO::PovExporter::m_outStream
std::ostream * m_outStream
Definition: PovExporter.h:175
agx::AgXString< std::string >
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agx::Vec3T< Real >
agxIO::PovExporter::m_aperture
static agx::Real m_aperture
Definition: PovExporter.h:179
agxIO::PovExporter::m_simulation
agxSDK::Simulation * m_simulation
Definition: PovExporter.h:173
agxIO::PovExporter::m_variance
static agx::Real m_variance
Definition: PovExporter.h:180
agxIO
The agxIO namespace contains classes for reading, writing and finding files.
Definition: Material.h:41
agxIO::PovExporter::cleanupString
agx::String cleanupString(const agx::String &in)
Translate any non-alphanumeric letters into '_'.
Definition: PovExporter.h:92