wrapper_collada.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
31 #ifndef _wrapper_collada_H_
32 #define _wrapper_collada_H_
33 
42 //####################################################################
45 
46 
47 //####################################################################
50 #include <ros/ros.h> /* Added by V. Santos, 15-Abr-2013,10:12 */
51 //dom
52 #include <dae.h>
53 #include <dom/domConstants.h>
54 #include <dom/domCOLLADA.h>
55 #include <dom/domProfile_common.h>
56 #include <dae/daeSIDResolver.h>
57 #include <dom/domInstance_controller.h>
58 #include <dae/domAny.h>
59 #include <dae/daeErrorHandler.h>
60 #include <dae/daeUtils.h>
61 #include <dom/domImage.h>
62 #include <modules/stdErrPlugin.h>
63 #include <dom/domEllipsoid.h>
64 #include <dom/domInput_global.h>
65 #include <dom/domAsset.h>
66 //#include <dom/domLimits_sub.h>
67 
68 //pcl
69 #include <pcl_ros/point_cloud.h>
70 #include <pcl/point_types.h>
71 
72 
73 //####################################################################
76 
77 using namespace ColladaDOM150;
78 
80 {
81  public:
82  wrapper_collada(std::string fl)
83  {
84  file_name = fl;
85  root = dae.add(file_name);
86  daeElement* asset = root->add("asset");
87  //daeElement* contributor = asset->add("contributor");
88  daeElement* created = asset->add("created");
89  daeElement* modified = asset->add("modified");
90  const char* date = "2008-04-08T13:07:52-08:00";
91  created->setCharData(date);
92  modified->setCharData(date);
93 
94  //Visual scene
95  daeElement* visualSceneLib = root->add("library_visual_scenes");
96  visualScene = visualSceneLib->add("visual_scene");
97  visualScene->setAttribute("id", "defaultScene");
98 
99  // Add a <scene>
100  root->add("scene instance_visual_scene")->setAttribute("url", makeUriRef("defaultScene").c_str());
101  }
102 
104 
105  void add_polygon_fixed_color(std::string polygon_name, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr normal, float r, float g, float b, float a);
106 
107  void add_polygon_fixed_color_on_both_sides(std::string polygon_name, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr normal, float r, float g, float b, float a)
108  {
109  //call the standard add_polygon_fixed_color
110  add_polygon_fixed_color(polygon_name, cloud, normal, r, g, b, a);
111 
112  //now call the same function with the fliped normal
113  //First flip the normal
114  pcl::PointCloud<pcl::PointXYZ> normal_flip;
115  pcl::PointXYZ p;
116  p.x = -normal->points[0].x;
117  p.y = -normal->points[0].y;
118  p.z = -normal->points[0].z;
119  normal_flip.points.push_back(p);
120 
121  //now reverse the cloud pts orientation
122  pcl::PointCloud<pcl::PointXYZ> cloud_flip;
123 
124  for (int i=((int)cloud->points.size()-1); i>=0; i--)
125  {
126  cloud_flip.points.push_back(cloud->points[i]);
127  }
128 
129  //Finally, add a new fliped polygon
130  add_polygon_fixed_color((polygon_name + "_flip").c_str(), cloud_flip.makeShared(), normal_flip.makeShared(), r, g, b, a);
131 
132  };
133 
134 
135  void write_file()
136  {
137  ROS_INFO("Writting collada file %s",file_name.c_str());
138  dae.writeAll();
139  }
140 
141 
142  private:
143 
144  DAE dae;
145  std::string file_name;
146  daeElement* root;
147  daeElement* visualScene;
148 
149  //private methods
150  void my_addInput(daeElement* triangles,
151  const std::string& semantic,
152  const std::string& srcID,
153  int offset);
154 
155 
156  std::string makeUriRef(const std::string& id);
157 
158  void my_addGeometry(daeElement* root);
159  void my_addVisualScene(daeElement* root);
160  void my_addEffect(daeElement* root);
161  void my_addMaterial(daeElement* root);
162  void my_addImage(daeElement* root);
163  void my_addSource(daeElement* mesh,
164  const std::string& srcID,
165  const std::string& paramNames,
166  domFloat values[],
167  int valueCount);
168  daeTArray<double> pcl_pointcloud_tp_daearray(pcl::PointCloud<pcl::PointXYZ>::Ptr pc);
169  template<typename T_wc>
170  daeTArray<T_wc> rawArrayToDaeArray(T_wc rawArray[], size_t count);
171 
172 };
173 
174 #endif
175 
wrapper_collada(std::string fl)
daeElement * root
void my_addVisualScene(daeElement *root)
Definition: export.cpp:219
void my_addInput(daeElement *triangles, const string &semantic, const string &srcID, int offset)
Definition: export.cpp:75
daeElement * visualScene
void my_addMaterial(daeElement *root)
Definition: export.cpp:209
string makeUriRef(const string &id)
Definition: export.cpp:36
void my_addSource(daeElement *mesh, const std::string &srcID, const std::string &paramNames, domFloat values[], int valueCount)
Definition: export.cpp:40
std::string file_name
void my_addGeometry(daeElement *root)
Definition: export.cpp:90
void add_polygon_fixed_color_on_both_sides(std::string polygon_name, pcl::PointCloud< pcl::PointXYZ >::Ptr cloud, pcl::PointCloud< pcl::PointXYZ >::Ptr normal, float r, float g, float b, float a)
void my_addEffect(daeElement *root)
Definition: export.cpp:186
void my_addImage(daeElement *root)
Definition: export.cpp:164
daeTArray< T > rawArrayToDaeArray(T rawArray[], size_t count)
Definition: export.cpp:28


wrapper_collada
Author(s): Miguel Oliveira
autogenerated on Mon Mar 2 2015 01:33:01