14 #include <hrpModel/ModelLoaderUtil.h> 19 using namespace scene;
20 using namespace video;
26 double i_origin[3],
double i_size[3]) :
27 ISceneNode(i_parent, i_mgr, i_id),
30 m_vertices[0] = vector3df(i_origin[0], -i_origin[1], i_origin[2]);
31 m_vertices[1] = vector3df(i_origin[0]+i_size[0], -i_origin[1], i_origin[2]);
32 m_vertices[2] = vector3df(i_origin[0]+i_size[0], -(i_origin[1]+i_size[1]), i_origin[2]);
33 m_vertices[3] = vector3df(i_origin[0], -(i_origin[1]+i_size[1]), i_origin[2]);
35 m_vertices[4] = m_vertices[0]; m_vertices[4].Z += i_size[2];
36 m_vertices[5] = m_vertices[1]; m_vertices[5].Z += i_size[2];
37 m_vertices[6] = m_vertices[2]; m_vertices[6].Z += i_size[2];
38 m_vertices[7] = m_vertices[3]; m_vertices[7].Z += i_size[2];
40 m_box.reset(m_vertices[0]);
41 for (
int i=1;
i<8;
i++) m_box.addInternalPoint(m_vertices[
i]);
44 m_cubeIndices[ 0] = 0; m_cubeIndices[ 1] = 1; m_cubeIndices[ 2] = 2;
45 m_cubeIndices[ 3] = 2; m_cubeIndices[ 4] = 3; m_cubeIndices[ 5] = 0;
47 m_cubeIndices[ 6] = 4; m_cubeIndices[ 7] = 5; m_cubeIndices[ 8] = 6;
48 m_cubeIndices[ 9] = 6; m_cubeIndices[10] = 7; m_cubeIndices[11] = 4;
50 m_cubeIndices[12] = 8; m_cubeIndices[13] = 9; m_cubeIndices[14] = 10;
51 m_cubeIndices[15] = 10; m_cubeIndices[16] = 11; m_cubeIndices[17] = 8;
53 m_cubeIndices[18] = 12; m_cubeIndices[19] = 13; m_cubeIndices[20] = 14;
54 m_cubeIndices[21] = 14; m_cubeIndices[22] = 15; m_cubeIndices[23] = 12;
56 m_cubeIndices[24] = 16; m_cubeIndices[25] = 17; m_cubeIndices[26] = 18;
57 m_cubeIndices[27] = 18; m_cubeIndices[28] = 19; m_cubeIndices[29] = 16;
59 m_cubeIndices[30] = 20; m_cubeIndices[31] = 21; m_cubeIndices[32] = 22;
60 m_cubeIndices[33] = 22; m_cubeIndices[34] = 23; m_cubeIndices[35] = 20;
63 void setMap(OpenHRP::OGMap3D *i_map) { m_map = i_map; }
66 SColor
white(0xff, 0xff, 0xff, 0xff);
68 m_cubeVerts[0] = S3DVertex(-i_res/2, -i_res/2, i_res/2,
70 m_cubeVerts[1] = S3DVertex( i_res/2, -i_res/2, i_res/2,
72 m_cubeVerts[2] = S3DVertex( i_res/2, i_res/2, i_res/2,
74 m_cubeVerts[3] = S3DVertex(-i_res/2, i_res/2, i_res/2,
77 m_cubeVerts[4] = S3DVertex(-i_res/2, i_res/2, -i_res/2,
79 m_cubeVerts[5] = S3DVertex( i_res/2, i_res/2, -i_res/2,
81 m_cubeVerts[6] = S3DVertex( i_res/2, -i_res/2, -i_res/2,
83 m_cubeVerts[7] = S3DVertex(-i_res/2, -i_res/2, -i_res/2,
86 m_cubeVerts[8] = S3DVertex(i_res/2, -i_res/2, i_res/2,
88 m_cubeVerts[9] = S3DVertex(i_res/2, -i_res/2, -i_res/2,
90 m_cubeVerts[10] = S3DVertex(i_res/2, i_res/2, -i_res/2,
92 m_cubeVerts[11] = S3DVertex(i_res/2, i_res/2, i_res/2,
95 m_cubeVerts[12] = S3DVertex(-i_res/2, i_res/2, i_res/2,
97 m_cubeVerts[13] = S3DVertex(-i_res/2, i_res/2, -i_res/2,
99 m_cubeVerts[14] = S3DVertex(-i_res/2, -i_res/2, -i_res/2,
101 m_cubeVerts[15] = S3DVertex(-i_res/2, -i_res/2, i_res/2,
104 m_cubeVerts[16] = S3DVertex(i_res/2, i_res/2, i_res/2,
106 m_cubeVerts[17] = S3DVertex(i_res/2, i_res/2, -i_res/2,
108 m_cubeVerts[18] = S3DVertex(-i_res/2,i_res/2, -i_res/2,
110 m_cubeVerts[19] = S3DVertex(-i_res/2,i_res/2, i_res/2,
113 m_cubeVerts[20] = S3DVertex(-i_res/2,-i_res/2, i_res/2,
115 m_cubeVerts[21] = S3DVertex(-i_res/2,-i_res/2, -i_res/2,
117 m_cubeVerts[22] = S3DVertex(i_res/2, -i_res/2, -i_res/2,
119 m_cubeVerts[23] = S3DVertex(i_res/2, -i_res/2, i_res/2,
125 SceneManager->registerNodeForRendering(
this);
127 ISceneNode::OnRegisterSceneNode();
130 IVideoDriver *driver = SceneManager->getVideoDriver();
132 driver->setTransform(ETS_WORLD, m);
135 driver->draw3DLine(m_vertices[0], m_vertices[1]);
136 driver->draw3DLine(m_vertices[1], m_vertices[2]);
137 driver->draw3DLine(m_vertices[2], m_vertices[3]);
138 driver->draw3DLine(m_vertices[3], m_vertices[0]);
140 driver->draw3DLine(m_vertices[4], m_vertices[5]);
141 driver->draw3DLine(m_vertices[5], m_vertices[6]);
142 driver->draw3DLine(m_vertices[6], m_vertices[7]);
143 driver->draw3DLine(m_vertices[7], m_vertices[4]);
145 driver->draw3DLine(m_vertices[0], m_vertices[4]);
146 driver->draw3DLine(m_vertices[1], m_vertices[5]);
147 driver->draw3DLine(m_vertices[2], m_vertices[6]);
148 driver->draw3DLine(m_vertices[3], m_vertices[7]);
151 setupCubeVertices(m_map->resolution);
152 double res = m_map->resolution;
154 int nxny = m_map->nx*m_map->ny;
156 for (
int i=0;
i<m_map->nx;
i++){
157 m[12] = m_map->pos.x +
i*res;
158 for (
int j=0;
j<m_map->ny;
j++){
159 m[13] = -(m_map->pos.y +
j*res);
160 for (
int k=0; k<m_map->nz; k++){
161 m[14] = m_map->pos.z + k*res;
162 unsigned char p = m_map->cells[rank++];
163 if (p != OpenHRP::gridUnknown
164 && p != OpenHRP::gridEmpty){
165 driver->setTransform(ETS_WORLD, m);
166 driver->drawIndexedTriangleList(m_cubeVerts, 24,
178 vector3df m_vertices[8];
179 S3DVertex m_tileVerts[4], m_cubeVerts[24];
180 u16 m_tileIndices[4], m_cubeIndices[36];
181 float m_scale[3], m_origin[3];
189 "implementation_id",
"OGMap3DViewer",
190 "type_name",
"OGMap3DViewer",
191 "description",
"null component",
192 "version", HRPSYS_PACKAGE_VERSION,
194 "category",
"example",
195 "activity_type",
"DataFlowComponent",
196 "max_instance",
"10",
198 "lang_type",
"compile",
200 "conf.default.generateImageSequence",
"0",
201 "conf.default.generateMovie",
"0",
202 "conf.default.xSize",
"4",
203 "conf.default.ySize",
"4",
204 "conf.default.zSize",
"4",
205 "conf.default.xOrigin",
"0",
206 "conf.default.yOrigin",
"-2",
207 "conf.default.zOrigin",
"0",
218 m_rpyIn(
"rpy", m_rpy),
219 m_OGMap3DServicePort(
"OGMap3DService"),
223 m_generateImageSequence(false),
227 m_generateMovie(false),
228 m_isGeneratingMovie(false)
240 std::cout <<
m_profile.instance_name <<
": onInitialize()" << std::endl;
303 std::cout <<
m_profile.instance_name<<
": onActivated(" << ec_id <<
")" << std::endl;
309 std::cout <<
m_profile.instance_name<<
": onDeactivated(" << ec_id <<
")" << std::endl;
313 void capture(
int w,
int h,
unsigned char *o_buffer)
315 glReadBuffer(GL_BACK);
316 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
317 for (
int i=0;
i<
h;
i++){
318 glReadPixels(0,(h-1-
i),w,1,GL_RGB,GL_UNSIGNED_BYTE,
323 void save(
int w,
int h,
const char *i_fname)
325 unsigned char *
buffer =
new unsigned char[w*h*3];
328 std::ofstream ofs(
"test.ppm", std::ios::out | std::ios::trunc | std::ios::binary );
331 ofs <<
"P6" << std::endl << buf << std::endl <<
"255" << std::endl;
332 for (
int i=h-1;
i>=0;
i--){
333 ofs.write((
char *)(buffer+
i*w*3), w*3);
352 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
353 int comPos = nameServer.find(
",");
355 comPos = nameServer.length();
357 nameServer = nameServer.substr(0, comPos);
359 if (prop[
"model"] !=
""){
360 std::cerr <<
"model = " << prop[
"model"] << std::endl;
362 prop[
"model"].c_str(),
363 CosNaming::NamingContext::_duplicate(
naming.getRootContext()));
375 OpenHRP::AABB region;
390 }
catch(CORBA::SystemException& ex){
415 std::string fname(
m_profile.instance_name);
419 CV_FOURCC(
'D',
'I',
'V',
'X'),
428 unsigned char rgb[camera->
width()*camera->
height()*3];
432 bgr[
i*3 ] = rgb[
i*3+2];
433 bgr[
i*3+1] = rgb[
i*3+1];
434 bgr[
i*3+2] = rgb[
i*3 ];
494 RTC::Create<OGMap3DViewer>,
495 RTC::Delete<OGMap3DViewer>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
void save(int w, int h, const char *i_fname)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
void draw(bool swap=true)
HRPMODEL_API OpenHRP::BodyInfo_var loadBodyInfo(const char *url, int &argc, char *argv[])
InPort< TimedDoubleSeq > m_qIn
void addBody(GLbody *i_body)
OGMap3DViewer(RTC::Manager *manager)
Constructor.
virtual const aabbox3d< f32 > & getBoundingBox() const
InPort< TimedPoint3D > m_pIn
void OGMap3DViewerInit(RTC::Manager *manager)
unsigned int m_imageCount
OpenHRP::OGMap3D * m_ogmap
coil::Properties & getProperties()
static Manager & instance()
irr::core::aabbox3d< f32 > m_box
RTC::CorbaConsumer< OpenHRP::OGMap3DService > m_OGMap3DService
bool m_generateImageSequence
static GLscene * getInstance()
virtual ~OGMap3DViewer()
Destructor.
coil::Properties & getConfig()
ExecutionContextHandle_t UniqueId
InPort< TimedOrientation3D > m_rpyIn
void setMap(OpenHRP::OGMap3D *i_map)
void setupCubeVertices(double i_res)
CMapSceneNode(ISceneNode *i_parent, ISceneManager *i_mgr, s32 i_id, double i_origin[3], double i_size[3])
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
RTC::CorbaPort m_OGMap3DServicePort
def j(str, encoding="cp932")
irr::scene::ISceneManager * getSceneManager()
CMapSceneNode * m_mapNode
CvVideoWriter * m_videoWriter
virtual void OnRegisterSceneNode()
static const char * nullcomponent_spec[]
virtual RTC::ReturnCode_t onInitialize()
void setPosture(const double *i_angles)
void capture(int w, int h, unsigned char *o_buffer)
std::string sprintf(char const *__restrict fmt,...)
png_infop png_bytep buffer
bool addPort(PortBase &port)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
bool addInPort(const char *name, InPortBase &inport)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
bool registerConsumer(const char *instance_name, const char *type_name, CorbaConsumerBase &consumer)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
virtual CORBA::Object_ptr getObject()