add segmentation mask rendering to TinyRenderer and shared memory API
similar to the zbuffer, but storing the object index (int) instead of float depth
This commit is contained in:
@@ -46,7 +46,11 @@ struct GUIHelperInterface
|
|||||||
|
|
||||||
virtual void resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ)=0;
|
virtual void resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ)=0;
|
||||||
|
|
||||||
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int destinationWidth, int destinationHeight, int* numPixelsCopied)=0;
|
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
|
||||||
|
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
|
||||||
|
float* depthBuffer, int depthBufferSizeInPixels,
|
||||||
|
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
|
||||||
|
int startPixelIndex, int destinationWidth, int destinationHeight, int* numPixelsCopied)=0;
|
||||||
|
|
||||||
virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) =0;
|
virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) =0;
|
||||||
|
|
||||||
@@ -107,7 +111,12 @@ struct DummyGUIHelper : public GUIHelperInterface
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int width, int height, int* numPixelsCopied)
|
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
|
||||||
|
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
|
||||||
|
float* depthBuffer, int depthBufferSizeInPixels,
|
||||||
|
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
|
||||||
|
int startPixelIndex, int width, int height, int* numPixelsCopied)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (numPixelsCopied)
|
if (numPixelsCopied)
|
||||||
*numPixelsCopied = 0;
|
*numPixelsCopied = 0;
|
||||||
|
|||||||
@@ -634,10 +634,12 @@ struct QuickCanvas : public Common2dCanvasInterface
|
|||||||
MyGraphWindow* m_gw[MAX_GRAPH_WINDOWS];
|
MyGraphWindow* m_gw[MAX_GRAPH_WINDOWS];
|
||||||
GraphingTexture* m_gt[MAX_GRAPH_WINDOWS];
|
GraphingTexture* m_gt[MAX_GRAPH_WINDOWS];
|
||||||
int m_curNumGraphWindows;
|
int m_curNumGraphWindows;
|
||||||
|
int m_curXpos;
|
||||||
|
|
||||||
QuickCanvas(GL3TexLoader* myTexLoader)
|
QuickCanvas(GL3TexLoader* myTexLoader)
|
||||||
:m_myTexLoader(myTexLoader),
|
:m_myTexLoader(myTexLoader),
|
||||||
m_curNumGraphWindows(0)
|
m_curNumGraphWindows(0),
|
||||||
|
m_curXpos(0)
|
||||||
{
|
{
|
||||||
for (int i=0;i<MAX_GRAPH_WINDOWS;i++)
|
for (int i=0;i<MAX_GRAPH_WINDOWS;i++)
|
||||||
{
|
{
|
||||||
@@ -661,7 +663,8 @@ struct QuickCanvas : public Common2dCanvasInterface
|
|||||||
MyGraphInput input(gui2->getInternalData());
|
MyGraphInput input(gui2->getInternalData());
|
||||||
input.m_width=width;
|
input.m_width=width;
|
||||||
input.m_height=height;
|
input.m_height=height;
|
||||||
input.m_xPos = 10000;//GUI will clamp it to the right//300;
|
input.m_xPos = m_curXpos;//GUI will clamp it to the right//300;
|
||||||
|
m_curXpos+=width+20;
|
||||||
input.m_yPos = 10000;//GUI will clamp it to bottom
|
input.m_yPos = 10000;//GUI will clamp it to bottom
|
||||||
input.m_name=canvasName;
|
input.m_name=canvasName;
|
||||||
input.m_texName = canvasName;
|
input.m_texName = canvasName;
|
||||||
|
|||||||
@@ -338,7 +338,12 @@ void OpenGLGuiHelper::resetCamera(float camDist, float pitch, float yaw, float c
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OpenGLGuiHelper::copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int destinationWidth, int destinationHeight, int* numPixelsCopied)
|
void OpenGLGuiHelper::copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
|
||||||
|
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
|
||||||
|
float* depthBuffer, int depthBufferSizeInPixels,
|
||||||
|
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
|
||||||
|
int startPixelIndex, int destinationWidth,
|
||||||
|
int destinationHeight, int* numPixelsCopied)
|
||||||
{
|
{
|
||||||
int sourceWidth = m_data->m_glApp->m_window->getWidth()*m_data->m_glApp->m_window->getRetinaScale();
|
int sourceWidth = m_data->m_glApp->m_window->getWidth()*m_data->m_glApp->m_window->getRetinaScale();
|
||||||
int sourceHeight = m_data->m_glApp->m_window->getHeight()*m_data->m_glApp->m_window->getRetinaScale();
|
int sourceHeight = m_data->m_glApp->m_window->getHeight()*m_data->m_glApp->m_window->getRetinaScale();
|
||||||
|
|||||||
@@ -44,7 +44,12 @@ struct OpenGLGuiHelper : public GUIHelperInterface
|
|||||||
|
|
||||||
virtual void resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ);
|
virtual void resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ);
|
||||||
|
|
||||||
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int destinationWidth, int destinationHeight, int* numPixelsCopied);
|
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
|
||||||
|
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
|
||||||
|
float* depthBuffer, int depthBufferSizeInPixels,
|
||||||
|
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
|
||||||
|
int startPixelIndex, int destinationWidth,
|
||||||
|
int destinationHeight, int* numPixelsCopied);
|
||||||
|
|
||||||
virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) ;
|
virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) ;
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ struct BulletURDFInternalData
|
|||||||
UrdfParser m_urdfParser;
|
UrdfParser m_urdfParser;
|
||||||
struct GUIHelperInterface* m_guiHelper;
|
struct GUIHelperInterface* m_guiHelper;
|
||||||
char m_pathPrefix[1024];
|
char m_pathPrefix[1024];
|
||||||
|
int m_bodyId;
|
||||||
btHashMap<btHashInt,btVector4> m_linkColors;
|
btHashMap<btHashInt,btVector4> m_linkColors;
|
||||||
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
|
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
|
||||||
|
|
||||||
@@ -209,6 +210,18 @@ const char* BulletURDFImporter::getPathPrefix()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BulletURDFImporter::setBodyUniqueId(int bodyId)
|
||||||
|
{
|
||||||
|
m_data->m_bodyId =bodyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int BulletURDFImporter::getBodyUniqueId() const
|
||||||
|
{
|
||||||
|
return m_data->m_bodyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BulletURDFImporter::~BulletURDFImporter()
|
BulletURDFImporter::~BulletURDFImporter()
|
||||||
{
|
{
|
||||||
delete m_data;
|
delete m_data;
|
||||||
@@ -1017,13 +1030,13 @@ bool BulletURDFImporter::getLinkContactInfo(int linkIndex, URDFLinkContactInfo&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BulletURDFImporter::convertLinkVisualShapes2(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, class btCollisionObject* colObj) const
|
void BulletURDFImporter::convertLinkVisualShapes2(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, class btCollisionObject* colObj, int objectIndex) const
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_data->m_customVisualShapesConverter)
|
if (m_data->m_customVisualShapesConverter)
|
||||||
{
|
{
|
||||||
const UrdfModel& model = m_data->m_urdfParser.getModel();
|
const UrdfModel& model = m_data->m_urdfParser.getModel();
|
||||||
m_data->m_customVisualShapesConverter->convertVisualShapes(linkIndex,pathPrefix,localInertiaFrame, model, colObj);
|
m_data->m_customVisualShapesConverter->convertVisualShapes(linkIndex,pathPrefix,localInertiaFrame, model, colObj, objectIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ public:
|
|||||||
virtual bool loadSDF(const char* fileName, bool forceFixedBase = false);
|
virtual bool loadSDF(const char* fileName, bool forceFixedBase = false);
|
||||||
virtual int getNumModels() const;
|
virtual int getNumModels() const;
|
||||||
virtual void activateModel(int modelIndex);
|
virtual void activateModel(int modelIndex);
|
||||||
|
virtual void setBodyUniqueId(int bodyId);
|
||||||
|
virtual int getBodyUniqueId() const;
|
||||||
const char* getPathPrefix();
|
const char* getPathPrefix();
|
||||||
|
|
||||||
void printTree(); //for debugging
|
void printTree(); //for debugging
|
||||||
@@ -50,7 +51,7 @@ public:
|
|||||||
|
|
||||||
virtual int convertLinkVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& inertialFrame) const;
|
virtual int convertLinkVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& inertialFrame) const;
|
||||||
|
|
||||||
virtual void convertLinkVisualShapes2(int linkIndex, const char* pathPrefix, const btTransform& inertialFrame, class btCollisionObject* colObj) const;
|
virtual void convertLinkVisualShapes2(int linkIndex, const char* pathPrefix, const btTransform& inertialFrame, class btCollisionObject* colObj, int objectIndex) const;
|
||||||
|
|
||||||
///todo(erwincoumans) refactor this convertLinkCollisionShapes/memory allocation
|
///todo(erwincoumans) refactor this convertLinkCollisionShapes/memory allocation
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
struct LinkVisualShapesConverter
|
struct LinkVisualShapesConverter
|
||||||
{
|
{
|
||||||
virtual void convertVisualShapes(int linkIndex, const char* pathPrefix, const class btTransform& localInertiaFrame, const struct UrdfModel& model, class btCollisionObject* colObj)=0;
|
virtual void convertVisualShapes(int linkIndex, const char* pathPrefix, const class btTransform& localInertiaFrame, const struct UrdfModel& model, class btCollisionObject* colObj, int objectIndex)=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //LINK_VISUAL_SHAPES_CONVERTER_H
|
#endif //LINK_VISUAL_SHAPES_CONVERTER_H
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ void ConvertURDF2BulletInternal(const URDFImporterInterface& u2b, MultiBodyCreat
|
|||||||
u2b.getLinkColor(urdfLinkIndex,color);
|
u2b.getLinkColor(urdfLinkIndex,color);
|
||||||
creation.createCollisionObjectGraphicsInstance(urdfLinkIndex,col,color);
|
creation.createCollisionObjectGraphicsInstance(urdfLinkIndex,col,color);
|
||||||
|
|
||||||
u2b.convertLinkVisualShapes2(urdfLinkIndex,pathPrefix,localInertialFrame,col);
|
u2b.convertLinkVisualShapes2(urdfLinkIndex,pathPrefix,localInertialFrame,col, u2b.getBodyUniqueId());
|
||||||
|
|
||||||
URDFLinkContactInfo contactInfo;
|
URDFLinkContactInfo contactInfo;
|
||||||
u2b.getLinkContactInfo(urdfLinkIndex,contactInfo);
|
u2b.getLinkContactInfo(urdfLinkIndex,contactInfo);
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ public:
|
|||||||
///quick hack: need to rethink the API/dependencies of this
|
///quick hack: need to rethink the API/dependencies of this
|
||||||
virtual int convertLinkVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& inertialFrame) const { return -1;}
|
virtual int convertLinkVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& inertialFrame) const { return -1;}
|
||||||
|
|
||||||
virtual void convertLinkVisualShapes2(int linkIndex, const char* pathPrefix, const btTransform& inertialFrame, class btCollisionObject* colObj) const { }
|
virtual void convertLinkVisualShapes2(int linkIndex, const char* pathPrefix, const btTransform& inertialFrame, class btCollisionObject* colObj, int objectIndex) const { }
|
||||||
|
virtual void setBodyUniqueId(int bodyId) {}
|
||||||
|
virtual int getBodyUniqueId() const { return 0;}
|
||||||
|
|
||||||
virtual class btCompoundShape* convertLinkCollisionShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const = 0;
|
virtual class btCompoundShape* convertLinkCollisionShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ struct TinyRendererSetupInternalData
|
|||||||
|
|
||||||
TGAImage m_rgbColorBuffer;
|
TGAImage m_rgbColorBuffer;
|
||||||
b3AlignedObjectArray<float> m_depthBuffer;
|
b3AlignedObjectArray<float> m_depthBuffer;
|
||||||
|
b3AlignedObjectArray<int> m_segmentationMaskBuffer;
|
||||||
|
|
||||||
|
|
||||||
int m_width;
|
int m_width;
|
||||||
@@ -185,7 +186,9 @@ TinyRendererSetup::TinyRendererSetup(struct GUIHelperInterface* gui)
|
|||||||
m_internalData->m_shapePtr.push_back(0);
|
m_internalData->m_shapePtr.push_back(0);
|
||||||
TinyRenderObjectData* ob = new TinyRenderObjectData(
|
TinyRenderObjectData* ob = new TinyRenderObjectData(
|
||||||
m_internalData->m_rgbColorBuffer,
|
m_internalData->m_rgbColorBuffer,
|
||||||
m_internalData->m_depthBuffer);
|
m_internalData->m_depthBuffer,
|
||||||
|
m_internalData->m_segmentationMaskBuffer,
|
||||||
|
m_internalData->m_renderObjects.size(),0);
|
||||||
//ob->loadModel("cube.obj");
|
//ob->loadModel("cube.obj");
|
||||||
const int* indices = &meshData.m_gfxShape->m_indices->at(0);
|
const int* indices = &meshData.m_gfxShape->m_indices->at(0);
|
||||||
ob->registerMeshShape(&meshData.m_gfxShape->m_vertices->at(0).xyzw[0],
|
ob->registerMeshShape(&meshData.m_gfxShape->m_vertices->at(0).xyzw[0],
|
||||||
|
|||||||
@@ -352,12 +352,19 @@ public:
|
|||||||
int m_rgbaBufferSizeInPixels;
|
int m_rgbaBufferSizeInPixels;
|
||||||
float* m_depthBuffer;
|
float* m_depthBuffer;
|
||||||
int m_depthBufferSizeInPixels;
|
int m_depthBufferSizeInPixels;
|
||||||
|
int* m_segmentationMaskBuffer;
|
||||||
|
int m_segmentationMaskBufferSizeInPixels;
|
||||||
int m_startPixelIndex;
|
int m_startPixelIndex;
|
||||||
int m_destinationWidth;
|
int m_destinationWidth;
|
||||||
int m_destinationHeight;
|
int m_destinationHeight;
|
||||||
int* m_numPixelsCopied;
|
int* m_numPixelsCopied;
|
||||||
|
|
||||||
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int destinationWidth, int destinationHeight, int* numPixelsCopied)
|
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
|
||||||
|
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
|
||||||
|
float* depthBuffer, int depthBufferSizeInPixels,
|
||||||
|
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
|
||||||
|
int startPixelIndex, int destinationWidth,
|
||||||
|
int destinationHeight, int* numPixelsCopied)
|
||||||
{
|
{
|
||||||
m_cs->lock();
|
m_cs->lock();
|
||||||
for (int i=0;i<16;i++)
|
for (int i=0;i<16;i++)
|
||||||
@@ -369,6 +376,8 @@ public:
|
|||||||
m_rgbaBufferSizeInPixels = rgbaBufferSizeInPixels;
|
m_rgbaBufferSizeInPixels = rgbaBufferSizeInPixels;
|
||||||
m_depthBuffer = depthBuffer;
|
m_depthBuffer = depthBuffer;
|
||||||
m_depthBufferSizeInPixels = depthBufferSizeInPixels;
|
m_depthBufferSizeInPixels = depthBufferSizeInPixels;
|
||||||
|
m_segmentationMaskBuffer = segmentationMaskBuffer;
|
||||||
|
m_segmentationMaskBufferSizeInPixels = segmentationMaskBufferSizeInPixels;
|
||||||
m_startPixelIndex = startPixelIndex;
|
m_startPixelIndex = startPixelIndex;
|
||||||
m_destinationWidth = destinationWidth;
|
m_destinationWidth = destinationWidth;
|
||||||
m_destinationHeight = destinationHeight;
|
m_destinationHeight = destinationHeight;
|
||||||
@@ -532,6 +541,8 @@ void b3RobotSimAPI::processMultiThreadedGraphicsRequests()
|
|||||||
m_data->m_multiThreadedHelper->m_rgbaBufferSizeInPixels,
|
m_data->m_multiThreadedHelper->m_rgbaBufferSizeInPixels,
|
||||||
m_data->m_multiThreadedHelper->m_depthBuffer,
|
m_data->m_multiThreadedHelper->m_depthBuffer,
|
||||||
m_data->m_multiThreadedHelper->m_depthBufferSizeInPixels,
|
m_data->m_multiThreadedHelper->m_depthBufferSizeInPixels,
|
||||||
|
m_data->m_multiThreadedHelper->m_segmentationMaskBuffer,
|
||||||
|
m_data->m_multiThreadedHelper->m_segmentationMaskBufferSizeInPixels,
|
||||||
m_data->m_multiThreadedHelper->m_startPixelIndex,
|
m_data->m_multiThreadedHelper->m_startPixelIndex,
|
||||||
m_data->m_multiThreadedHelper->m_destinationWidth,
|
m_data->m_multiThreadedHelper->m_destinationWidth,
|
||||||
m_data->m_multiThreadedHelper->m_destinationHeight,
|
m_data->m_multiThreadedHelper->m_destinationHeight,
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ protected:
|
|||||||
int m_selectedBody;
|
int m_selectedBody;
|
||||||
int m_prevSelectedBody;
|
int m_prevSelectedBody;
|
||||||
struct Common2dCanvasInterface* m_canvas;
|
struct Common2dCanvasInterface* m_canvas;
|
||||||
int m_canvasIndex;
|
int m_canvasRGBIndex;
|
||||||
|
int m_canvasDepthIndex;
|
||||||
|
int m_canvasSegMaskIndex;
|
||||||
|
|
||||||
void createButton(const char* name, int id, bool isTrigger );
|
void createButton(const char* name, int id, bool isTrigger );
|
||||||
|
|
||||||
@@ -248,7 +250,7 @@ void PhysicsClientExample::prepareAndSubmitCommand(int commandId)
|
|||||||
|
|
||||||
case CMD_LOAD_SDF:
|
case CMD_LOAD_SDF:
|
||||||
{
|
{
|
||||||
b3SharedMemoryCommandHandle commandHandle = b3LoadSdfCommandInit(m_physicsClientHandle, "kuka_iiwa/model.sdf");
|
b3SharedMemoryCommandHandle commandHandle = b3LoadSdfCommandInit(m_physicsClientHandle, "two_cubes.sdf");//kuka_iiwa/model.sdf");
|
||||||
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -460,7 +462,11 @@ m_prevSelectedBody(-1),
|
|||||||
m_numMotors(0),
|
m_numMotors(0),
|
||||||
m_options(options),
|
m_options(options),
|
||||||
m_isOptionalServerConnected(false),
|
m_isOptionalServerConnected(false),
|
||||||
m_canvas(0)
|
m_canvas(0),
|
||||||
|
m_canvasRGBIndex(-1),
|
||||||
|
m_canvasDepthIndex(-1),
|
||||||
|
m_canvasSegMaskIndex(-1)
|
||||||
|
|
||||||
{
|
{
|
||||||
b3Printf("Started PhysicsClientExample\n");
|
b3Printf("Started PhysicsClientExample\n");
|
||||||
}
|
}
|
||||||
@@ -479,9 +485,15 @@ PhysicsClientExample::~PhysicsClientExample()
|
|||||||
m_physicsServer.disconnectSharedMemory(deInitializeSharedMemory);
|
m_physicsServer.disconnectSharedMemory(deInitializeSharedMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_canvas && (m_canvasIndex>=0))
|
if (m_canvas)
|
||||||
{
|
{
|
||||||
m_canvas->destroyCanvas(m_canvasIndex);
|
if (m_canvasRGBIndex>=0)
|
||||||
|
m_canvas->destroyCanvas(m_canvasRGBIndex);
|
||||||
|
if (m_canvasDepthIndex>=0)
|
||||||
|
m_canvas->destroyCanvas(m_canvasDepthIndex);
|
||||||
|
if (m_canvasSegMaskIndex>=0)
|
||||||
|
m_canvas->destroyCanvas(m_canvasSegMaskIndex);
|
||||||
|
|
||||||
}
|
}
|
||||||
b3Printf("~PhysicsClientExample\n");
|
b3Printf("~PhysicsClientExample\n");
|
||||||
}
|
}
|
||||||
@@ -614,8 +626,9 @@ void PhysicsClientExample::initPhysics()
|
|||||||
if (m_canvas)
|
if (m_canvas)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
m_canvasRGBIndex = m_canvas->createCanvas("Synthetic Camera RGB data",camVisualizerWidth, camVisualizerHeight);
|
||||||
m_canvasIndex = m_canvas->createCanvas("Synthetic Camera",camVisualizerWidth, camVisualizerHeight);
|
m_canvasDepthIndex = m_canvas->createCanvas("Synthetic Camera Depth data",camVisualizerWidth, camVisualizerHeight);
|
||||||
|
m_canvasSegMaskIndex = m_canvas->createCanvas("Synthetic Camera Segmentation Mask",camVisualizerWidth, camVisualizerHeight);
|
||||||
|
|
||||||
for (int i=0;i<camVisualizerWidth;i++)
|
for (int i=0;i<camVisualizerWidth;i++)
|
||||||
{
|
{
|
||||||
@@ -631,10 +644,16 @@ void PhysicsClientExample::initPhysics()
|
|||||||
green=0;
|
green=0;
|
||||||
blue=0;
|
blue=0;
|
||||||
}
|
}
|
||||||
m_canvas->setPixel(m_canvasIndex,i,j,red,green,blue,alpha);
|
m_canvas->setPixel(m_canvasRGBIndex,i,j,red,green,blue,alpha);
|
||||||
|
m_canvas->setPixel(m_canvasDepthIndex,i,j,red,green,blue,alpha);
|
||||||
|
m_canvas->setPixel(m_canvasSegMaskIndex,i,j,red,green,blue,alpha);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_canvas->refreshImageData(m_canvasIndex);
|
m_canvas->refreshImageData(m_canvasRGBIndex);
|
||||||
|
m_canvas->refreshImageData(m_canvasDepthIndex);
|
||||||
|
m_canvas->refreshImageData(m_canvasSegMaskIndex);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,8 +717,36 @@ void PhysicsClientExample::stepSimulation(float deltaTime)
|
|||||||
// sprintf(msg,"Camera image %d OK\n",counter++);
|
// sprintf(msg,"Camera image %d OK\n",counter++);
|
||||||
b3CameraImageData imageData;
|
b3CameraImageData imageData;
|
||||||
b3GetCameraImageData(m_physicsClientHandle,&imageData);
|
b3GetCameraImageData(m_physicsClientHandle,&imageData);
|
||||||
if (m_canvas && m_canvasIndex >=0)
|
if (m_canvas)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//compute depth image range
|
||||||
|
float minDepthValue = 1e20f;
|
||||||
|
float maxDepthValue = -1e20f;
|
||||||
|
|
||||||
|
for (int i=0;i<camVisualizerWidth;i++)
|
||||||
|
{
|
||||||
|
for (int j=0;j<camVisualizerHeight;j++)
|
||||||
|
{
|
||||||
|
int xIndex = int(float(i)*(float(imageData.m_pixelWidth)/float(camVisualizerWidth)));
|
||||||
|
int yIndex = int(float(j)*(float(imageData.m_pixelHeight)/float(camVisualizerHeight)));
|
||||||
|
btClamp(yIndex,0,imageData.m_pixelHeight);
|
||||||
|
btClamp(xIndex,0,imageData.m_pixelWidth);
|
||||||
|
|
||||||
|
if (m_canvasDepthIndex >=0)
|
||||||
|
{
|
||||||
|
int depthPixelIndex = (xIndex+yIndex*imageData.m_pixelWidth);
|
||||||
|
float depthValue = imageData.m_depthValues4[depthPixelIndex];
|
||||||
|
//todo: rescale the depthValue to [0..255]
|
||||||
|
if (depthValue>-1e20)
|
||||||
|
{
|
||||||
|
maxDepthValue = btMax(maxDepthValue,depthValue);
|
||||||
|
minDepthValue = btMin(minDepthValue,depthValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i=0;i<camVisualizerWidth;i++)
|
for (int i=0;i<camVisualizerWidth;i++)
|
||||||
{
|
{
|
||||||
for (int j=0;j<camVisualizerHeight;j++)
|
for (int j=0;j<camVisualizerHeight;j++)
|
||||||
@@ -710,15 +757,76 @@ void PhysicsClientExample::stepSimulation(float deltaTime)
|
|||||||
btClamp(xIndex,0,imageData.m_pixelWidth);
|
btClamp(xIndex,0,imageData.m_pixelWidth);
|
||||||
int bytesPerPixel = 4; //RGBA
|
int bytesPerPixel = 4; //RGBA
|
||||||
|
|
||||||
int pixelIndex = (xIndex+yIndex*imageData.m_pixelWidth)*bytesPerPixel;
|
if (m_canvasRGBIndex >=0)
|
||||||
m_canvas->setPixel(m_canvasIndex,i,j,
|
{
|
||||||
imageData.m_rgbColorData[pixelIndex],
|
int rgbPixelIndex = (xIndex+yIndex*imageData.m_pixelWidth)*bytesPerPixel;
|
||||||
imageData.m_rgbColorData[pixelIndex+1],
|
m_canvas->setPixel(m_canvasRGBIndex,i,j,
|
||||||
imageData.m_rgbColorData[pixelIndex+2],
|
imageData.m_rgbColorData[rgbPixelIndex],
|
||||||
255); //alpha set to 255
|
imageData.m_rgbColorData[rgbPixelIndex+1],
|
||||||
|
imageData.m_rgbColorData[rgbPixelIndex+2],
|
||||||
|
255); //alpha set to 255
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_canvasDepthIndex >=0)
|
||||||
|
{
|
||||||
|
int depthPixelIndex = (xIndex+yIndex*imageData.m_pixelWidth);
|
||||||
|
float depthValue = imageData.m_depthValues4[depthPixelIndex];
|
||||||
|
//todo: rescale the depthValue to [0..255]
|
||||||
|
if (depthValue>-1e20)
|
||||||
|
{
|
||||||
|
int rgb = (depthValue-minDepthValue)*(255. / (btFabs(maxDepthValue-minDepthValue)));
|
||||||
|
if (rgb<0 || rgb>255)
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("rgb=%d\n",rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_canvas->setPixel(m_canvasDepthIndex,i,j,
|
||||||
|
rgb,
|
||||||
|
rgb,
|
||||||
|
255, 255); //alpha set to 255
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
m_canvas->setPixel(m_canvasDepthIndex,i,j,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, 255); //alpha set to 255
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_canvasSegMaskIndex>=0 && (0!=imageData.m_segmentationMaskValues))
|
||||||
|
{
|
||||||
|
int segmentationMaskPixelIndex = (xIndex+yIndex*imageData.m_pixelWidth);
|
||||||
|
int segmentationMask = imageData.m_segmentationMaskValues[segmentationMaskPixelIndex];
|
||||||
|
btVector4 palette[4] = {btVector4(32,255,32,255),
|
||||||
|
btVector4(32,32,255,255),
|
||||||
|
btVector4(255,255,32,255),
|
||||||
|
btVector4(32,255,255,255)};
|
||||||
|
if (segmentationMask>=0)
|
||||||
|
{
|
||||||
|
btVector4 rgb = palette[segmentationMask&3];
|
||||||
|
m_canvas->setPixel(m_canvasSegMaskIndex,i,j,
|
||||||
|
rgb.x(),
|
||||||
|
rgb.y(),
|
||||||
|
rgb.z(), 255); //alpha set to 255
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
m_canvas->setPixel(m_canvasSegMaskIndex,i,j,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, 255); //alpha set to 255
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_canvas->refreshImageData(m_canvasIndex);
|
if (m_canvasRGBIndex >=0)
|
||||||
|
m_canvas->refreshImageData(m_canvasRGBIndex);
|
||||||
|
if (m_canvasDepthIndex >=0)
|
||||||
|
m_canvas->refreshImageData(m_canvasDepthIndex);
|
||||||
|
if (m_canvasSegMaskIndex >=0)
|
||||||
|
m_canvas->refreshImageData(m_canvasSegMaskIndex);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// b3Printf(msg);
|
// b3Printf(msg);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ struct PhysicsClientSharedMemoryInternalData {
|
|||||||
int m_cachedCameraPixelsHeight;
|
int m_cachedCameraPixelsHeight;
|
||||||
btAlignedObjectArray<unsigned char> m_cachedCameraPixelsRGBA;
|
btAlignedObjectArray<unsigned char> m_cachedCameraPixelsRGBA;
|
||||||
btAlignedObjectArray<float> m_cachedCameraDepthBuffer;
|
btAlignedObjectArray<float> m_cachedCameraDepthBuffer;
|
||||||
|
btAlignedObjectArray<int> m_cachedSegmentationMaskBuffer;
|
||||||
|
|
||||||
btAlignedObjectArray<int> m_bodyIdsRequestInfo;
|
btAlignedObjectArray<int> m_bodyIdsRequestInfo;
|
||||||
SharedMemoryStatus m_tempBackupServerStatus;
|
SharedMemoryStatus m_tempBackupServerStatus;
|
||||||
@@ -514,6 +515,7 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
|
|||||||
|
|
||||||
m_data->m_cachedCameraPixelsRGBA.reserve(numPixels*numBytesPerPixel);
|
m_data->m_cachedCameraPixelsRGBA.reserve(numPixels*numBytesPerPixel);
|
||||||
m_data->m_cachedCameraDepthBuffer.resize(numTotalPixels);
|
m_data->m_cachedCameraDepthBuffer.resize(numTotalPixels);
|
||||||
|
m_data->m_cachedSegmentationMaskBuffer.resize(numTotalPixels);
|
||||||
m_data->m_cachedCameraPixelsRGBA.resize(numTotalPixels*numBytesPerPixel);
|
m_data->m_cachedCameraPixelsRGBA.resize(numTotalPixels*numBytesPerPixel);
|
||||||
|
|
||||||
|
|
||||||
@@ -522,12 +524,18 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
|
|||||||
// printf("pixel = %d\n", rgbaPixelsReceived[0]);
|
// printf("pixel = %d\n", rgbaPixelsReceived[0]);
|
||||||
|
|
||||||
float* depthBuffer = (float*)&(m_data->m_testBlock1->m_bulletStreamDataServerToClientRefactor[serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*4]);
|
float* depthBuffer = (float*)&(m_data->m_testBlock1->m_bulletStreamDataServerToClientRefactor[serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*4]);
|
||||||
|
int* segmentationMaskBuffer = (int*)&(m_data->m_testBlock1->m_bulletStreamDataServerToClientRefactor[serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*8]);
|
||||||
|
|
||||||
for (int i=0;i<serverCmd.m_sendPixelDataArguments.m_numPixelsCopied;i++)
|
for (int i=0;i<serverCmd.m_sendPixelDataArguments.m_numPixelsCopied;i++)
|
||||||
{
|
{
|
||||||
m_data->m_cachedCameraDepthBuffer[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex] = depthBuffer[i];
|
m_data->m_cachedCameraDepthBuffer[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex] = depthBuffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i=0;i<serverCmd.m_sendPixelDataArguments.m_numPixelsCopied;i++)
|
||||||
|
{
|
||||||
|
m_data->m_cachedSegmentationMaskBuffer[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex] = segmentationMaskBuffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
for (int i=0;i<serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*numBytesPerPixel;i++)
|
for (int i=0;i<serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*numBytesPerPixel;i++)
|
||||||
{
|
{
|
||||||
m_data->m_cachedCameraPixelsRGBA[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex*numBytesPerPixel]
|
m_data->m_cachedCameraPixelsRGBA[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex*numBytesPerPixel]
|
||||||
@@ -704,8 +712,9 @@ void PhysicsClientSharedMemory::getCachedCameraImage(struct b3CameraImageData* c
|
|||||||
{
|
{
|
||||||
cameraData->m_pixelWidth = m_data->m_cachedCameraPixelsWidth;
|
cameraData->m_pixelWidth = m_data->m_cachedCameraPixelsWidth;
|
||||||
cameraData->m_pixelHeight = m_data->m_cachedCameraPixelsHeight;
|
cameraData->m_pixelHeight = m_data->m_cachedCameraPixelsHeight;
|
||||||
cameraData->m_depthValues = m_data->m_cachedCameraDepthBuffer.size() ? &m_data->m_cachedCameraDepthBuffer[0] : 0;
|
cameraData->m_depthValues4 = m_data->m_cachedCameraDepthBuffer.size() ? &m_data->m_cachedCameraDepthBuffer[0] : 0;
|
||||||
cameraData->m_rgbColorData = m_data->m_cachedCameraPixelsRGBA.size() ? &m_data->m_cachedCameraPixelsRGBA[0] : 0;
|
cameraData->m_rgbColorData = m_data->m_cachedCameraPixelsRGBA.size() ? &m_data->m_cachedCameraPixelsRGBA[0] : 0;
|
||||||
|
cameraData->m_segmentationMaskValues = m_data->m_cachedSegmentationMaskBuffer.size()?&m_data->m_cachedSegmentationMaskBuffer[0] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* PhysicsClientSharedMemory::getDebugLinesFrom() const {
|
const float* PhysicsClientSharedMemory::getDebugLinesFrom() const {
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ struct PhysicsDirectInternalData
|
|||||||
int m_cachedCameraPixelsHeight;
|
int m_cachedCameraPixelsHeight;
|
||||||
btAlignedObjectArray<unsigned char> m_cachedCameraPixelsRGBA;
|
btAlignedObjectArray<unsigned char> m_cachedCameraPixelsRGBA;
|
||||||
btAlignedObjectArray<float> m_cachedCameraDepthBuffer;
|
btAlignedObjectArray<float> m_cachedCameraDepthBuffer;
|
||||||
|
btAlignedObjectArray<int> m_cachedSegmentationMask;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PhysicsServerCommandProcessor* m_commandProcessor;
|
PhysicsServerCommandProcessor* m_commandProcessor;
|
||||||
@@ -205,6 +207,7 @@ bool PhysicsDirect::processCamera(const struct SharedMemoryCommand& orgCommand)
|
|||||||
|
|
||||||
m_data->m_cachedCameraPixelsRGBA.reserve(numPixels*numBytesPerPixel);
|
m_data->m_cachedCameraPixelsRGBA.reserve(numPixels*numBytesPerPixel);
|
||||||
m_data->m_cachedCameraDepthBuffer.resize(numTotalPixels);
|
m_data->m_cachedCameraDepthBuffer.resize(numTotalPixels);
|
||||||
|
m_data->m_cachedSegmentationMask.resize(numTotalPixels);
|
||||||
m_data->m_cachedCameraPixelsRGBA.resize(numTotalPixels*numBytesPerPixel);
|
m_data->m_cachedCameraPixelsRGBA.resize(numTotalPixels*numBytesPerPixel);
|
||||||
|
|
||||||
|
|
||||||
@@ -212,6 +215,7 @@ bool PhysicsDirect::processCamera(const struct SharedMemoryCommand& orgCommand)
|
|||||||
(unsigned char*)&m_data->m_bulletStreamDataServerToClient[0];
|
(unsigned char*)&m_data->m_bulletStreamDataServerToClient[0];
|
||||||
|
|
||||||
float* depthBuffer = (float*)&(m_data->m_bulletStreamDataServerToClient[serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*4]);
|
float* depthBuffer = (float*)&(m_data->m_bulletStreamDataServerToClient[serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*4]);
|
||||||
|
int* segmentationMaskBuffer = (int*)&(m_data->m_bulletStreamDataServerToClient[serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*8]);
|
||||||
|
|
||||||
// printf("pixel = %d\n", rgbaPixelsReceived[0]);
|
// printf("pixel = %d\n", rgbaPixelsReceived[0]);
|
||||||
|
|
||||||
@@ -219,6 +223,10 @@ bool PhysicsDirect::processCamera(const struct SharedMemoryCommand& orgCommand)
|
|||||||
{
|
{
|
||||||
m_data->m_cachedCameraDepthBuffer[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex] = depthBuffer[i];
|
m_data->m_cachedCameraDepthBuffer[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex] = depthBuffer[i];
|
||||||
}
|
}
|
||||||
|
for (int i=0;i<serverCmd.m_sendPixelDataArguments.m_numPixelsCopied;i++)
|
||||||
|
{
|
||||||
|
m_data->m_cachedSegmentationMask[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex] = segmentationMaskBuffer[i];
|
||||||
|
}
|
||||||
for (int i=0;i<serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*numBytesPerPixel;i++)
|
for (int i=0;i<serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*numBytesPerPixel;i++)
|
||||||
{
|
{
|
||||||
m_data->m_cachedCameraPixelsRGBA[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex*numBytesPerPixel]
|
m_data->m_cachedCameraPixelsRGBA[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex*numBytesPerPixel]
|
||||||
@@ -456,7 +464,8 @@ void PhysicsDirect::getCachedCameraImage(b3CameraImageData* cameraData)
|
|||||||
{
|
{
|
||||||
cameraData->m_pixelWidth = m_data->m_cachedCameraPixelsWidth;
|
cameraData->m_pixelWidth = m_data->m_cachedCameraPixelsWidth;
|
||||||
cameraData->m_pixelHeight = m_data->m_cachedCameraPixelsHeight;
|
cameraData->m_pixelHeight = m_data->m_cachedCameraPixelsHeight;
|
||||||
cameraData->m_depthValues = m_data->m_cachedCameraDepthBuffer.size() ? &m_data->m_cachedCameraDepthBuffer[0] : 0;
|
cameraData->m_depthValues4 = m_data->m_cachedCameraDepthBuffer.size() ? &m_data->m_cachedCameraDepthBuffer[0] : 0;
|
||||||
cameraData->m_rgbColorData = m_data->m_cachedCameraPixelsRGBA.size() ? &m_data->m_cachedCameraPixelsRGBA[0] : 0;
|
cameraData->m_rgbColorData = m_data->m_cachedCameraPixelsRGBA.size() ? &m_data->m_cachedCameraPixelsRGBA[0] : 0;
|
||||||
|
cameraData->m_segmentationMaskValues = m_data->m_cachedSegmentationMask.size()? &m_data->m_cachedSegmentationMask[0] : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -751,7 +751,7 @@ bool PhysicsServerCommandProcessor::loadSdf(const char* fileName, char* bufferSe
|
|||||||
int bodyUniqueId = m_data->allocHandle();
|
int bodyUniqueId = m_data->allocHandle();
|
||||||
|
|
||||||
InternalBodyHandle* bodyHandle = m_data->getHandle(bodyUniqueId);
|
InternalBodyHandle* bodyHandle = m_data->getHandle(bodyUniqueId);
|
||||||
|
u2b.setBodyUniqueId(bodyUniqueId);
|
||||||
{
|
{
|
||||||
btScalar mass = 0;
|
btScalar mass = 0;
|
||||||
bodyHandle->m_rootLocalInertialFrame.setIdentity();
|
bodyHandle->m_rootLocalInertialFrame.setIdentity();
|
||||||
@@ -845,6 +845,7 @@ bool PhysicsServerCommandProcessor::loadUrdf(const char* fileName, const btVecto
|
|||||||
if (bodyUniqueIdPtr)
|
if (bodyUniqueIdPtr)
|
||||||
*bodyUniqueIdPtr= bodyUniqueId;
|
*bodyUniqueIdPtr= bodyUniqueId;
|
||||||
|
|
||||||
|
u2b.setBodyUniqueId(bodyUniqueId);
|
||||||
InternalBodyHandle* bodyHandle = m_data->getHandle(bodyUniqueId);
|
InternalBodyHandle* bodyHandle = m_data->getHandle(bodyUniqueId);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -1165,15 +1166,21 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
|||||||
|
|
||||||
if (numRemainingPixels>0)
|
if (numRemainingPixels>0)
|
||||||
{
|
{
|
||||||
int maxNumPixels = bufferSizeInBytes/8-1;
|
int totalBytesPerPixel = 4+4+4;//4 for rgb, 4 for depth, 4 for segmentation mask
|
||||||
|
int maxNumPixels = bufferSizeInBytes/totalBytesPerPixel-1;
|
||||||
unsigned char* pixelRGBA = (unsigned char*)bufferServerToClient;
|
unsigned char* pixelRGBA = (unsigned char*)bufferServerToClient;
|
||||||
int numRequestedPixels = btMin(maxNumPixels,numRemainingPixels);
|
int numRequestedPixels = btMin(maxNumPixels,numRemainingPixels);
|
||||||
|
|
||||||
float* depthBuffer = (float*)(bufferServerToClient+numRequestedPixels*4);
|
float* depthBuffer = (float*)(bufferServerToClient+numRequestedPixels*4);
|
||||||
|
int* segmentationMaskBuffer = (int*)(bufferServerToClient+numRequestedPixels*8);
|
||||||
|
|
||||||
if ((clientCmd.m_updateFlags & ER_BULLET_HARDWARE_OPENGL)!=0)
|
if ((clientCmd.m_updateFlags & ER_BULLET_HARDWARE_OPENGL)!=0)
|
||||||
{
|
{
|
||||||
m_data->m_guiHelper->copyCameraImageData(clientCmd.m_requestPixelDataArguments.m_viewMatrix,clientCmd.m_requestPixelDataArguments.m_projectionMatrix,pixelRGBA,numRequestedPixels,depthBuffer,numRequestedPixels,startPixelIndex,width,height,&numPixelsCopied);
|
m_data->m_guiHelper->copyCameraImageData(clientCmd.m_requestPixelDataArguments.m_viewMatrix,
|
||||||
|
clientCmd.m_requestPixelDataArguments.m_projectionMatrix,pixelRGBA,numRequestedPixels,
|
||||||
|
depthBuffer,numRequestedPixels,
|
||||||
|
segmentationMaskBuffer, numRequestedPixels,
|
||||||
|
startPixelIndex,width,height,&numPixelsCopied);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -1194,7 +1201,10 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_data->m_visualConverter.copyCameraImageData(pixelRGBA,numRequestedPixels,depthBuffer,numRequestedPixels,startPixelIndex,&width,&height,&numPixelsCopied);
|
m_data->m_visualConverter.copyCameraImageData(pixelRGBA,numRequestedPixels,
|
||||||
|
depthBuffer,numRequestedPixels,
|
||||||
|
segmentationMaskBuffer, numRequestedPixels,
|
||||||
|
startPixelIndex,&width,&height,&numPixelsCopied);
|
||||||
}
|
}
|
||||||
|
|
||||||
//each pixel takes 4 RGBA values and 1 float = 8 bytes
|
//each pixel takes 4 RGBA values and 1 float = 8 bytes
|
||||||
|
|||||||
@@ -400,12 +400,19 @@ public:
|
|||||||
int m_rgbaBufferSizeInPixels;
|
int m_rgbaBufferSizeInPixels;
|
||||||
float* m_depthBuffer;
|
float* m_depthBuffer;
|
||||||
int m_depthBufferSizeInPixels;
|
int m_depthBufferSizeInPixels;
|
||||||
|
int* m_segmentationMaskBuffer;
|
||||||
|
int m_segmentationMaskBufferSizeInPixels;
|
||||||
int m_startPixelIndex;
|
int m_startPixelIndex;
|
||||||
int m_destinationWidth;
|
int m_destinationWidth;
|
||||||
int m_destinationHeight;
|
int m_destinationHeight;
|
||||||
int* m_numPixelsCopied;
|
int* m_numPixelsCopied;
|
||||||
|
|
||||||
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int destinationWidth, int destinationHeight, int* numPixelsCopied)
|
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
|
||||||
|
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
|
||||||
|
float* depthBuffer, int depthBufferSizeInPixels,
|
||||||
|
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
|
||||||
|
int startPixelIndex, int destinationWidth,
|
||||||
|
int destinationHeight, int* numPixelsCopied)
|
||||||
{
|
{
|
||||||
m_cs->lock();
|
m_cs->lock();
|
||||||
for (int i=0;i<16;i++)
|
for (int i=0;i<16;i++)
|
||||||
@@ -417,6 +424,8 @@ public:
|
|||||||
m_rgbaBufferSizeInPixels = rgbaBufferSizeInPixels;
|
m_rgbaBufferSizeInPixels = rgbaBufferSizeInPixels;
|
||||||
m_depthBuffer = depthBuffer;
|
m_depthBuffer = depthBuffer;
|
||||||
m_depthBufferSizeInPixels = depthBufferSizeInPixels;
|
m_depthBufferSizeInPixels = depthBufferSizeInPixels;
|
||||||
|
m_segmentationMaskBuffer = segmentationMaskBuffer;
|
||||||
|
m_segmentationMaskBufferSizeInPixels = segmentationMaskBufferSizeInPixels;
|
||||||
m_startPixelIndex = startPixelIndex;
|
m_startPixelIndex = startPixelIndex;
|
||||||
m_destinationWidth = destinationWidth;
|
m_destinationWidth = destinationWidth;
|
||||||
m_destinationHeight = destinationHeight;
|
m_destinationHeight = destinationHeight;
|
||||||
@@ -768,6 +777,8 @@ void PhysicsServerExample::stepSimulation(float deltaTime)
|
|||||||
m_multiThreadedHelper->m_rgbaBufferSizeInPixels,
|
m_multiThreadedHelper->m_rgbaBufferSizeInPixels,
|
||||||
m_multiThreadedHelper->m_depthBuffer,
|
m_multiThreadedHelper->m_depthBuffer,
|
||||||
m_multiThreadedHelper->m_depthBufferSizeInPixels,
|
m_multiThreadedHelper->m_depthBufferSizeInPixels,
|
||||||
|
m_multiThreadedHelper->m_segmentationMaskBuffer,
|
||||||
|
m_multiThreadedHelper->m_segmentationMaskBufferSizeInPixels,
|
||||||
m_multiThreadedHelper->m_startPixelIndex,
|
m_multiThreadedHelper->m_startPixelIndex,
|
||||||
m_multiThreadedHelper->m_destinationWidth,
|
m_multiThreadedHelper->m_destinationWidth,
|
||||||
m_multiThreadedHelper->m_destinationHeight,
|
m_multiThreadedHelper->m_destinationHeight,
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ struct b3CameraImageData
|
|||||||
int m_pixelWidth;
|
int m_pixelWidth;
|
||||||
int m_pixelHeight;
|
int m_pixelHeight;
|
||||||
const unsigned char* m_rgbColorData;//3*m_pixelWidth*m_pixelHeight bytes
|
const unsigned char* m_rgbColorData;//3*m_pixelWidth*m_pixelHeight bytes
|
||||||
const float* m_depthValues;//m_pixelWidth*m_pixelHeight floats
|
const float* m_depthValues4;//m_pixelWidth*m_pixelHeight floats
|
||||||
|
const int* m_segmentationMaskValues;//m_pixelWidth*m_pixelHeight ints
|
||||||
};
|
};
|
||||||
|
|
||||||
///b3LinkState provides extra information such as the Cartesian world coordinates
|
///b3LinkState provides extra information such as the Cartesian world coordinates
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ struct TinyRendererVisualShapeConverterInternalData
|
|||||||
int m_swHeight;
|
int m_swHeight;
|
||||||
TGAImage m_rgbColorBuffer;
|
TGAImage m_rgbColorBuffer;
|
||||||
b3AlignedObjectArray<float> m_depthBuffer;
|
b3AlignedObjectArray<float> m_depthBuffer;
|
||||||
|
b3AlignedObjectArray<int> m_segmentationMaskBuffer;
|
||||||
|
|
||||||
SimpleCamera m_camera;
|
SimpleCamera m_camera;
|
||||||
|
|
||||||
TinyRendererVisualShapeConverterInternalData()
|
TinyRendererVisualShapeConverterInternalData()
|
||||||
@@ -75,6 +77,7 @@ struct TinyRendererVisualShapeConverterInternalData
|
|||||||
m_rgbColorBuffer(START_WIDTH,START_HEIGHT,TGAImage::RGB)
|
m_rgbColorBuffer(START_WIDTH,START_HEIGHT,TGAImage::RGB)
|
||||||
{
|
{
|
||||||
m_depthBuffer.resize(m_swWidth*m_swHeight);
|
m_depthBuffer.resize(m_swWidth*m_swHeight);
|
||||||
|
m_segmentationMaskBuffer.resize(m_swWidth*m_swHeight,-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -440,7 +443,7 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void TinyRendererVisualShapeConverter::convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfModel& model, class btCollisionObject* colObj)
|
void TinyRendererVisualShapeConverter::convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfModel& model, class btCollisionObject* colObj, int objectIndex)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@@ -487,7 +490,7 @@ void TinyRendererVisualShapeConverter::convertVisualShapes(int linkIndex, const
|
|||||||
|
|
||||||
if (vertices.size() && indices.size())
|
if (vertices.size() && indices.size())
|
||||||
{
|
{
|
||||||
TinyRenderObjectData* tinyObj = new TinyRenderObjectData(m_data->m_rgbColorBuffer,m_data->m_depthBuffer);
|
TinyRenderObjectData* tinyObj = new TinyRenderObjectData(m_data->m_rgbColorBuffer,m_data->m_depthBuffer, m_data->m_segmentationMaskBuffer, objectIndex,0);
|
||||||
unsigned char* textureImage=0;
|
unsigned char* textureImage=0;
|
||||||
int textureWidth=0;
|
int textureWidth=0;
|
||||||
int textureHeight=0;
|
int textureHeight=0;
|
||||||
@@ -535,6 +538,7 @@ void TinyRendererVisualShapeConverter::clearBuffers(TGAColor& clearColor)
|
|||||||
{
|
{
|
||||||
m_data->m_rgbColorBuffer.set(x,y,clearColor);
|
m_data->m_rgbColorBuffer.set(x,y,clearColor);
|
||||||
m_data->m_depthBuffer[x+y*m_data->m_swWidth] = -1e30f;
|
m_data->m_depthBuffer[x+y*m_data->m_swWidth] = -1e30f;
|
||||||
|
m_data->m_segmentationMaskBuffer[x+y*m_data->m_swWidth] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -624,7 +628,7 @@ void TinyRendererVisualShapeConverter::render(const float viewMat[16], const flo
|
|||||||
// printf("flipped!\n");
|
// printf("flipped!\n");
|
||||||
m_data->m_rgbColorBuffer.flip_vertically();
|
m_data->m_rgbColorBuffer.flip_vertically();
|
||||||
|
|
||||||
//flip z-buffer
|
//flip z-buffer and segmentation Buffer
|
||||||
{
|
{
|
||||||
int half = m_data->m_swHeight>>1;
|
int half = m_data->m_swHeight>>1;
|
||||||
for (int j=0; j<half; j++)
|
for (int j=0; j<half; j++)
|
||||||
@@ -634,6 +638,7 @@ void TinyRendererVisualShapeConverter::render(const float viewMat[16], const flo
|
|||||||
for (int i=0;i<m_data->m_swWidth;i++)
|
for (int i=0;i<m_data->m_swWidth;i++)
|
||||||
{
|
{
|
||||||
btSwap(m_data->m_depthBuffer[l1+i],m_data->m_depthBuffer[l2+i]);
|
btSwap(m_data->m_depthBuffer[l1+i],m_data->m_depthBuffer[l2+i]);
|
||||||
|
btSwap(m_data->m_segmentationMaskBuffer[l1+i],m_data->m_segmentationMaskBuffer[l2+i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -652,11 +657,16 @@ void TinyRendererVisualShapeConverter::setWidthAndHeight(int width, int height)
|
|||||||
m_data->m_swHeight = height;
|
m_data->m_swHeight = height;
|
||||||
|
|
||||||
m_data->m_depthBuffer.resize(m_data->m_swWidth*m_data->m_swHeight);
|
m_data->m_depthBuffer.resize(m_data->m_swWidth*m_data->m_swHeight);
|
||||||
|
m_data->m_segmentationMaskBuffer.resize(m_data->m_swWidth*m_data->m_swHeight);
|
||||||
m_data->m_rgbColorBuffer = TGAImage(width, height, TGAImage::RGB);
|
m_data->m_rgbColorBuffer = TGAImage(width, height, TGAImage::RGB);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int* widthPtr, int* heightPtr, int* numPixelsCopied)
|
void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
|
||||||
|
float* depthBuffer, int depthBufferSizeInPixels,
|
||||||
|
int* segmentationMaskBuffer, int segmentationMaskSizeInPixels,
|
||||||
|
int startPixelIndex, int* widthPtr, int* heightPtr, int* numPixelsCopied)
|
||||||
{
|
{
|
||||||
int w = m_data->m_rgbColorBuffer.get_width();
|
int w = m_data->m_rgbColorBuffer.get_width();
|
||||||
int h = m_data->m_rgbColorBuffer.get_height();
|
int h = m_data->m_rgbColorBuffer.get_height();
|
||||||
@@ -682,6 +692,11 @@ void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixels
|
|||||||
{
|
{
|
||||||
depthBuffer[i] = m_data->m_depthBuffer[i+startPixelIndex];
|
depthBuffer[i] = m_data->m_depthBuffer[i+startPixelIndex];
|
||||||
}
|
}
|
||||||
|
if (segmentationMaskBuffer)
|
||||||
|
{
|
||||||
|
segmentationMaskBuffer[i] = m_data->m_segmentationMaskBuffer[i+startPixelIndex];
|
||||||
|
}
|
||||||
|
|
||||||
if (pixelsRGBA)
|
if (pixelsRGBA)
|
||||||
{
|
{
|
||||||
pixelsRGBA[i*numBytesPerPixel] = m_data->m_rgbColorBuffer.buffer()[(i+startPixelIndex)*3+0];
|
pixelsRGBA[i*numBytesPerPixel] = m_data->m_rgbColorBuffer.buffer()[(i+startPixelIndex)*3+0];
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ struct TinyRendererVisualShapeConverter : public LinkVisualShapesConverter
|
|||||||
|
|
||||||
virtual ~TinyRendererVisualShapeConverter();
|
virtual ~TinyRendererVisualShapeConverter();
|
||||||
|
|
||||||
virtual void convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfModel& model, class btCollisionObject* colShape);
|
virtual void convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfModel& model, class btCollisionObject* colShape, int objectIndex);
|
||||||
|
|
||||||
void setUpAxis(int axis);
|
void setUpAxis(int axis);
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ struct TinyRendererVisualShapeConverter : public LinkVisualShapesConverter
|
|||||||
void getWidthAndHeight(int& width, int& height);
|
void getWidthAndHeight(int& width, int& height);
|
||||||
void setWidthAndHeight(int width, int height);
|
void setWidthAndHeight(int width, int height);
|
||||||
|
|
||||||
void copyCameraImageData(unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int* widthPtr, int* heightPtr, int* numPixelsCopied);
|
void copyCameraImageData(unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels,int* segmentationMaskBuffer, int segmentationMaskSizeInPixels, int startPixelIndex, int* widthPtr, int* heightPtr, int* numPixelsCopied);
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
void render(const float viewMat[16], const float projMat[16]);
|
void render(const float viewMat[16], const float projMat[16]);
|
||||||
|
|||||||
@@ -88,12 +88,14 @@ struct Shader : public IShader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TinyRenderObjectData::TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray<float>&depthBuffer)
|
TinyRenderObjectData::TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray<float>&depthBuffer, b3AlignedObjectArray<int>& segmentationMaskBuffer, int objectIndex,int objectIndex2)
|
||||||
:m_rgbColorBuffer(rgbColorBuffer),
|
:m_rgbColorBuffer(rgbColorBuffer),
|
||||||
m_depthBuffer(depthBuffer),
|
m_depthBuffer(depthBuffer),
|
||||||
|
m_segmentationMaskBuffer(segmentationMaskBuffer),
|
||||||
m_model(0),
|
m_model(0),
|
||||||
m_userData(0),
|
m_userData(0),
|
||||||
m_userIndex(-1)
|
m_userIndex(-1),
|
||||||
|
m_objectIndex(objectIndex)
|
||||||
{
|
{
|
||||||
Vec3f eye(1,1,3);
|
Vec3f eye(1,1,3);
|
||||||
Vec3f center(0,0,0);
|
Vec3f center(0,0,0);
|
||||||
@@ -247,6 +249,7 @@ void TinyRenderer::renderObject(TinyRenderObjectData& renderData)
|
|||||||
renderData.m_viewportMatrix = viewport(0,0,width, height);
|
renderData.m_viewportMatrix = viewport(0,0,width, height);
|
||||||
|
|
||||||
b3AlignedObjectArray<float>& zbuffer = renderData.m_depthBuffer;
|
b3AlignedObjectArray<float>& zbuffer = renderData.m_depthBuffer;
|
||||||
|
b3AlignedObjectArray<int>& segmentationMaskBuffer = renderData.m_segmentationMaskBuffer;
|
||||||
|
|
||||||
TGAImage& frame = renderData.m_rgbColorBuffer;
|
TGAImage& frame = renderData.m_rgbColorBuffer;
|
||||||
|
|
||||||
@@ -264,7 +267,7 @@ void TinyRenderer::renderObject(TinyRenderObjectData& renderData)
|
|||||||
for (int j=0; j<3; j++) {
|
for (int j=0; j<3; j++) {
|
||||||
shader.vertex(i, j);
|
shader.vertex(i, j);
|
||||||
}
|
}
|
||||||
triangle(shader.varying_tri, shader, frame, &zbuffer[0], renderData.m_viewportMatrix);
|
triangle(shader.varying_tri, shader, frame, &zbuffer[0], &segmentationMaskBuffer[0], renderData.m_viewportMatrix, renderData.m_objectIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ struct TinyRenderObjectData
|
|||||||
|
|
||||||
TGAImage& m_rgbColorBuffer;
|
TGAImage& m_rgbColorBuffer;
|
||||||
b3AlignedObjectArray<float>& m_depthBuffer;
|
b3AlignedObjectArray<float>& m_depthBuffer;
|
||||||
|
b3AlignedObjectArray<int>& m_segmentationMaskBuffer;
|
||||||
|
|
||||||
TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray<float>& depthBuffer);
|
TinyRenderObjectData(TGAImage& rgbColorBuffer,b3AlignedObjectArray<float>&depthBuffer, b3AlignedObjectArray<int>& segmentationMaskBuffer,int objectIndex,int objectIndex2);
|
||||||
virtual ~TinyRenderObjectData();
|
virtual ~TinyRenderObjectData();
|
||||||
|
|
||||||
void loadModel(const char* fileName);
|
void loadModel(const char* fileName);
|
||||||
@@ -41,6 +42,7 @@ struct TinyRenderObjectData
|
|||||||
|
|
||||||
void* m_userData;
|
void* m_userData;
|
||||||
int m_userIndex;
|
int m_userIndex;
|
||||||
|
int m_objectIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ Vec3f barycentric(Vec2f A, Vec2f B, Vec2f C, Vec2f P) {
|
|||||||
return Vec3f(-1,1,1); // in this case generate negative coordinates, it will be thrown away by the rasterizator
|
return Vec3f(-1,1,1); // in this case generate negative coordinates, it will be thrown away by the rasterizator
|
||||||
}
|
}
|
||||||
|
|
||||||
void triangle(mat<4,3,float> &clipc, IShader &shader, TGAImage &image, float *zbuffer, const Matrix& viewPortMatrix) {
|
void triangle(mat<4,3,float> &clipc, IShader &shader, TGAImage &image, float *zbuffer, int* segmentationMaskBuffer, const Matrix& viewPortMatrix, int objectIndex) {
|
||||||
mat<3,4,float> pts = (viewPortMatrix*clipc).transpose(); // transposed to ease access to each of the points
|
mat<3,4,float> pts = (viewPortMatrix*clipc).transpose(); // transposed to ease access to each of the points
|
||||||
|
|
||||||
|
|
||||||
@@ -100,6 +100,7 @@ void triangle(mat<4,3,float> &clipc, IShader &shader, TGAImage &image, float *zb
|
|||||||
bool discard = shader.fragment(bc_clip, color);
|
bool discard = shader.fragment(bc_clip, color);
|
||||||
if (!discard) {
|
if (!discard) {
|
||||||
zbuffer[P.x+P.y*image.get_width()] = frag_depth;
|
zbuffer[P.x+P.y*image.get_width()] = frag_depth;
|
||||||
|
segmentationMaskBuffer[P.x+P.y*image.get_width()] = objectIndex;
|
||||||
image.set(P.x, P.y, color);
|
image.set(P.x, P.y, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ struct IShader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//void triangle(Vec4f *pts, IShader &shader, TGAImage &image, float *zbuffer);
|
//void triangle(Vec4f *pts, IShader &shader, TGAImage &image, float *zbuffer);
|
||||||
void triangle(mat<4,3,float> &pts, IShader &shader, TGAImage &image, float *zbuffer, const Matrix& viewPortMatrix);
|
void triangle(mat<4,3,float> &pts, IShader &shader, TGAImage &image, float *zbuffer, int* segmentationMaskBuffer, const Matrix& viewPortMatrix, int objectIndex);
|
||||||
#endif //__OUR_GL_H__
|
#endif //__OUR_GL_H__
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user