Skip to content
Permalink
Browse files

Point cloud update vertex positions and colors #58

#58

Signed-off-by: Peter Kovacs <peter.kovacs@sztaki.mta.hu>
  • Loading branch information...
pkovacs86 committed Nov 20, 2017
1 parent e1e9367 commit e68b02adc2c6371fdc00fbd217f3aaa931597820
@@ -232,6 +232,8 @@ namespace Ape
SKY_DELETE,
POINT_CLOUD_CREATE = (POINT_CLOUD << 8) + 1,
POINT_CLOUD_PARAMETERS,
POINT_CLOUD_POINTS,
POINT_CLOUD_COLORS,
POINT_CLOUD_PARENTNODE,
POINT_CLOUD_DELETE,
ET_INVALID
@@ -39,18 +39,21 @@ namespace Ape
{
Ape::PointCloudPoints points;
Ape::PointCloudColors colors;
float boundigSphereRadius;

struct PointCloudSetParameters
()
{
this->points = Ape::PointCloudPoints();
this->colors = Ape::PointCloudColors();
this->boundigSphereRadius = 0.0f;
}

struct PointCloudSetParameters(Ape::PointCloudPoints points, Ape::PointCloudColors colors)
struct PointCloudSetParameters(Ape::PointCloudPoints points, Ape::PointCloudColors colors, float boundigSphereRadius)
{
this->points = points;
this->colors = colors;
this->boundigSphereRadius = boundigSphereRadius;
}

Ape::PointCloudPoints getPoints()
@@ -63,6 +66,11 @@ namespace Ape
return colors;
}

float getBoundigSphereRadius()
{
return boundigSphereRadius;
}

std::string toString() const
{
std::ostringstream buff;
@@ -75,6 +83,8 @@ namespace Ape
for (auto const &item : colors) buff << item << ", ";
buff << ")" << std::endl;

buff << "BoundigSphereRadius(" << boundigSphereRadius << ")" << std::endl;

return buff.str();
}
};
@@ -87,10 +97,18 @@ namespace Ape
virtual ~IPointCloud() {};

public:
virtual void setParameters(Ape::PointCloudPoints points, Ape::PointCloudColors colors) = 0;
virtual void setParameters(Ape::PointCloudPoints points, Ape::PointCloudColors colors, float boundigSphereRadius) = 0;

virtual Ape::PointCloudSetParameters getParameters() = 0;

virtual void updatePoints(Ape::PointCloudPoints points) = 0;

virtual void updateColors(Ape::PointCloudColors colors) = 0;

virtual Ape::PointCloudPoints getCurrentPoints() = 0;

virtual Ape::PointCloudColors getCurrentColors() = 0;

virtual void setParentNode(Ape::NodeWeakPtr parentNode) = 0;

virtual Ape::NodeWeakPtr getParentNode() = 0;
@@ -29,17 +29,20 @@ Ape::PointCloudImpl::PointCloudImpl(std::string name, bool isHostCreated) : Ape:
mParentNode = Ape::NodeWeakPtr();
mParentNodeName = std::string();
mParameters = Ape::PointCloudSetParameters();
mCurrentPoints = Ape::PointCloudPoints();
mCurrentColors = Ape::PointCloudColors();
}

Ape::PointCloudImpl::~PointCloudImpl()
{

}

void Ape::PointCloudImpl::setParameters(Ape::PointCloudPoints points, Ape::PointCloudColors colors)
void Ape::PointCloudImpl::setParameters(Ape::PointCloudPoints points, Ape::PointCloudColors colors, float boundigSphereRadius)
{
mParameters.points = points;
mParameters.colors = colors;
mParameters.boundigSphereRadius = boundigSphereRadius;
mpEventManagerImpl->fireEvent(Ape::Event(mName, Ape::Event::Type::POINT_CLOUD_PARAMETERS));
}

@@ -48,6 +51,28 @@ Ape::PointCloudSetParameters Ape::PointCloudImpl::getParameters()
return mParameters;
}

void Ape::PointCloudImpl::updatePoints(Ape::PointCloudPoints points)
{
mCurrentPoints = points;
mpEventManagerImpl->fireEvent(Ape::Event(mName, Ape::Event::Type::POINT_CLOUD_POINTS));
}

void Ape::PointCloudImpl::updateColors(Ape::PointCloudColors colors)
{
mCurrentColors = colors;
mpEventManagerImpl->fireEvent(Ape::Event(mName, Ape::Event::Type::POINT_CLOUD_COLORS));
}

Ape::PointCloudPoints Ape::PointCloudImpl::getCurrentPoints()
{
return mCurrentPoints;
}

Ape::PointCloudColors Ape::PointCloudImpl::getCurrentColors()
{
return mCurrentColors;
}


void Ape::PointCloudImpl::setParentNode(Ape::NodeWeakPtr parentNode)
{
@@ -78,6 +103,8 @@ RakNet::RM3SerializationResult Ape::PointCloudImpl::Serialize(RakNet::SerializeP
serializeParameters->pro[0].reliability = RELIABLE_ORDERED;
mVariableDeltaSerializer.BeginIdenticalSerialize(&serializationContext, serializeParameters->whenLastSerialized == 0, &serializeParameters->outputBitstream[0]);
mVariableDeltaSerializer.SerializeVariable(&serializationContext, mParameters);
mVariableDeltaSerializer.SerializeVariable(&serializationContext, mCurrentPoints);
mVariableDeltaSerializer.SerializeVariable(&serializationContext, mCurrentColors);
mVariableDeltaSerializer.SerializeVariable(&serializationContext, RakNet::RakString(mParentNodeName.c_str()));
mVariableDeltaSerializer.EndSerialize(&serializationContext);
return RakNet::RM3SR_SERIALIZED_ALWAYS;
@@ -89,6 +116,10 @@ void Ape::PointCloudImpl::Deserialize(RakNet::DeserializeParameters *deserialize
mVariableDeltaSerializer.BeginDeserialize(&deserializationContext, &deserializeParameters->serializationBitstream[0]);
if (mVariableDeltaSerializer.DeserializeVariable(&deserializationContext, mParameters))
mpEventManagerImpl->fireEvent(Ape::Event(mName, Ape::Event::Type::POINT_CLOUD_PARAMETERS));
if (mVariableDeltaSerializer.DeserializeVariable(&deserializationContext, mCurrentPoints))
mpEventManagerImpl->fireEvent(Ape::Event(mName, Ape::Event::Type::POINT_CLOUD_POINTS));
if (mVariableDeltaSerializer.DeserializeVariable(&deserializationContext, mCurrentColors))
mpEventManagerImpl->fireEvent(Ape::Event(mName, Ape::Event::Type::POINT_CLOUD_COLORS));
RakNet::RakString parentNodeName;
if (mVariableDeltaSerializer.DeserializeVariable(&deserializationContext, parentNodeName))
{
@@ -38,10 +38,18 @@ namespace Ape

~PointCloudImpl();

void setParameters(Ape::PointCloudPoints points, Ape::PointCloudColors colors) override;
void setParameters(Ape::PointCloudPoints points, Ape::PointCloudColors colors, float boundigSphereRadius) override;

Ape::PointCloudSetParameters getParameters() override;

void updatePoints(Ape::PointCloudPoints points) override;

void updateColors(Ape::PointCloudColors colors) override;

Ape::PointCloudPoints getCurrentPoints() override;

Ape::PointCloudColors getCurrentColors() override;

void setParentNode(Ape::NodeWeakPtr parentNode) override;

Ape::NodeWeakPtr getParentNode() override;
@@ -62,6 +70,10 @@ namespace Ape
std::string mParentNodeName;

Ape::PointCloudSetParameters mParameters;

Ape::PointCloudPoints mCurrentPoints;

Ape::PointCloudColors mCurrentColors;
};
}

@@ -75,6 +75,7 @@ void Ape::CefRenderHandlerImpl::mouseClick(int browserID, CefBrowserHost::MouseB
cefMouseEvent.x = mMouseCurrentPosition.x;
cefMouseEvent.y = mMouseCurrentPosition.y;
mBrowsers[browserID]->GetHost()->SendMouseClickEvent(cefMouseEvent, mouseButtonType, false, 0);
std::cout << "Ape:::CefRenderHandlerImpl::mouseClick " << "x:" << cefMouseEvent.x << " y:" << cefMouseEvent.y << " type:" << mouseButtonType << std::endl;
}
}

@@ -88,5 +89,6 @@ void Ape::CefRenderHandlerImpl::mouseMoved(int browserID, int x, int y)
cefMouseEvent.x = mMouseCurrentPosition.x;
cefMouseEvent.y = mMouseCurrentPosition.y;
mBrowsers[browserID]->GetHost()->SendMouseMoveEvent(cefMouseEvent, false);
std::cout << "Ape:::CefRenderHandlerImpl::mouseMoved " << "x:" << cefMouseEvent.x << " y:" << cefMouseEvent.y << std::endl;
}
}
@@ -22,8 +22,9 @@ SOFTWARE.*/

#include "ApeOgrePointCloud.h"

Ape::OgrePointCloud::OgrePointCloud(const std::string& name, const std::string& resourcegroup, const int numpoints, float *parray, float *carray)
Ape::OgrePointCloud::OgrePointCloud(const std::string& name, const std::string& resourcegroup, const int numpoints, float *parray, float *carray, float boundigSphereRadius)
{
mRenderSystemForVertex = Ogre::Root::getSingleton().getRenderSystem();
Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton().createManual(name, resourcegroup);
Ogre::SubMesh* sub = msh->createSubMesh();
msh->sharedVertexData = new Ogre::VertexData();
@@ -54,6 +55,7 @@ Ape::OgrePointCloud::OgrePointCloud(const std::string& name, const std::string&
}
sub->useSharedVertices = true;
sub->operationType = Ogre::RenderOperation::OT_POINT_LIST;
msh->_setBoundingSphereRadius(boundigSphereRadius);
msh->load();
}

@@ -76,12 +78,12 @@ void Ape::OgrePointCloud::updateVertexPositions(int size, float *points)

void Ape::OgrePointCloud::updateVertexColours(int size, float *colours)
{
float *pCArray = static_cast<float*>(mCbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
Ogre::RGBA *colorArrayBuffer = static_cast<Ogre::RGBA*>(mCbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
int j = 0;
for (int i = 0; i < size * 3; i += 3)
{
pCArray[i] = colours[i];
pCArray[i + 1] = colours[i + 1];
pCArray[i + 2] = colours[i + 2];
Ogre::ColourValue color = Ogre::ColourValue(colours[i], colours[i + 1], colours[i + 2]);
mRenderSystemForVertex->convertColourValue(color, &colorArrayBuffer[j++]);
}
mCbuf->unlock();
}
@@ -29,7 +29,7 @@ namespace Ape {
class OgrePointCloud
{
public:
OgrePointCloud(const std::string& name, const std::string& resourcegroup, const int numpoints, float *parray, float *carray);
OgrePointCloud(const std::string& name, const std::string& resourcegroup, const int numpoints, float *parray, float *carray, float boundigSphereRadius);

void updateVertexPositions(int size, float *points);

@@ -43,6 +43,8 @@ namespace Ape {
Ogre::HardwareVertexBufferSharedPtr mVbuf;

Ogre::HardwareVertexBufferSharedPtr mCbuf;

Ogre::RenderSystem* mRenderSystemForVertex;
};
}
#endif
@@ -80,6 +80,7 @@ Ape::OgreRenderPlugin::OgreRenderPlugin( )
mpSkyxSunlight = nullptr;
mpSkyxSkylight = nullptr;
mpSkyxBasicController = nullptr;
mOgrePointCloudMeshes = std::map<std::string, Ape::OgrePointCloud*>();
}

Ape::OgreRenderPlugin::~OgreRenderPlugin()
@@ -1787,13 +1788,32 @@ void Ape::OgreRenderPlugin::processEventDoubleQueue()
int size = pointCloudParameters.points.size() / 3;
float* points = &pointCloudParameters.points[0];
float* colors = &pointCloudParameters.colors[0];
if (auto ogrePointCloudMesh = new Ape::OgrePointCloud(pointCloudName + "Mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, size, points, colors))
if (auto ogrePointCloudMesh = new Ape::OgrePointCloud(pointCloudName + "Mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, size, points, colors, pointCloudParameters.boundigSphereRadius))
{
if (auto ogreEntity = mpSceneMgr->createEntity(pointCloudName, pointCloudName + "Mesh"))
{
ogreEntity->setMaterialName("Pointcloud");
mOgrePointCloudMeshes[pointCloudName + "Mesh"] = ogrePointCloudMesh;
}
}
}
break;
case Ape::Event::Type::POINT_CLOUD_POINTS:
{
Ape::PointCloudPoints points = pointCloud->getCurrentPoints();
int size = points.size() / 3;
float* pPoints = &points[0];
mOgrePointCloudMeshes[pointCloudName + "Mesh"]->updateVertexPositions(size, pPoints);
}
break;
case Ape::Event::Type::POINT_CLOUD_COLORS:
{
Ape::PointCloudColors colors = pointCloud->getCurrentColors();
int size = colors.size() / 3;
float* pColors = &colors[0];
mOgrePointCloudMeshes[pointCloudName + "Mesh"]->updateVertexColours(size, pColors);
}
break;
case Ape::Event::Type::POINT_CLOUD_PARENTNODE:
{
if (mpSceneMgr->hasEntity(pointCloudName))
@@ -204,6 +204,8 @@ namespace Ape

Ape::NodeWeakPtr mUserNode;

std::map<std::string, Ape::OgrePointCloud*> mOgrePointCloudMeshes;

void processEventDoubleQueue();

void eventCallBack(const Ape::Event& event);
@@ -7,7 +7,7 @@ material Pointcloud
diffuse vertexcolour
specular vertexcolour
ambient vertexcolour
point_size 0.1
point_size 0.01
point_sprites on
point_size_attenuation on
}
@@ -9,6 +9,7 @@ ApeTesterPlugin::ApeTesterPlugin()
mpScene = Ape::IScene::getSingletonPtr();
mInterpolators = std::vector<std::unique_ptr<Ape::Interpolator>>();
mDemoObjectNode = Ape::NodeWeakPtr();
mPointCloud = Ape::PointCloudWeakPtr();
}

ApeTesterPlugin::~ApeTesterPlugin()
@@ -339,18 +340,19 @@ void ApeTesterPlugin::Init()
3, 0, 0
};
Ape::PointCloudColors colors = {
1, 1, 1,
1, 1, 1,
1, 1, 1,
1, 1, 1,
1, 1, 1,
1, 1, 1,
1, 1, 1,
1, 1, 1,
1, 1, 1
(float)0.9, 0, 0,
(float)0.9, 0, 0,
(float)0.9, 0, 0,
(float)0.9, 0, 0,
(float)0.9, 0, 0,
(float)0.9, 0, 0,
(float)0.9, 0, 0,
(float)0.9, 0, 0,
(float)0.9, 0, 0
};
pointCloud->setParameters(points, colors);
pointCloud->setParameters(points, colors, 100.0f);
pointCloud->setParentNode(pointCloudNode);
mPointCloud = pointCloud;
}
}
if (auto demoObjectNode = mDemoObjectNode.lock())
@@ -392,7 +394,7 @@ void ApeTesterPlugin::Run()
double duration = 0;
while (true)
{
auto start = std::chrono::high_resolution_clock::now();
/*auto start = std::chrono::high_resolution_clock::now();
if (!mInterpolators.empty())
{
for (std::vector<std::unique_ptr<Ape::Interpolator>>::iterator it = mInterpolators.begin(); it != mInterpolators.end();)
@@ -416,7 +418,46 @@ void ApeTesterPlugin::Run()
}
duration = 0;
}
duration = duration + std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - start).count();
duration = duration + std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - start).count();*/

if (auto pointCloud = mPointCloud.lock())
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distInt(-5, 3);
std::vector<double> randomPoints;
for (int i = 0; i < 9; i++)
randomPoints.push_back(distInt(gen));
Ape::PointCloudPoints points = {
(float)randomPoints[0], 0, 0,
(float)randomPoints[1], 0, 0,
(float)randomPoints[2], 0, 0,
(float)randomPoints[3], 0, 0,
(float)randomPoints[4], 0, 0,
(float)randomPoints[5], 0, 0,
(float)randomPoints[6], 0, 0,
(float)randomPoints[7], 0, 0,
(float)randomPoints[8], 0, 0
};
std::uniform_real_distribution<double> distDouble(0.0, 1.0);
std::vector<double> randomRedColors;
for (int i = 0; i < 9; i++)
randomRedColors.push_back(distDouble(gen));
Ape::PointCloudColors colors = {
(float)randomRedColors[0], 0, 0,
(float)randomRedColors[1], 0, 0,
(float)randomRedColors[2], 0, 0,
(float)randomRedColors[3], 0, 0,
(float)randomRedColors[4], 0, 0,
(float)randomRedColors[5], 0, 0,
(float)randomRedColors[6], 0, 0,
(float)randomRedColors[7], 0, 0,
(float)randomRedColors[8], 0, 0
};
pointCloud->updatePoints(points);
pointCloud->updateColors(colors);
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
mpEventManager->disconnectEvent(Ape::Event::Group::NODE, std::bind(&ApeTesterPlugin::eventCallBack, this, std::placeholders::_1));
}
Oops, something went wrong.

0 comments on commit e68b02a

Please sign in to comment.
You can’t perform that action at this time.