-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit == ngsmith/calvr_plugins
- Loading branch information
Marcin Rogowski
committed
Mar 15, 2013
0 parents
commit d16c181
Showing
22 changed files
with
11,529 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
SET(LIB_NAME KinectDemo) | ||
|
||
SET(PLUGIN_HEADERS | ||
KinectDemo.h | ||
Skeleton.h | ||
MCylinder.h | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/skeletonframe.pb.h | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/skeleton.pb.h | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/colormap.pb.h | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/depthmap.pb.h | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/pointcloud.pb.h | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/packing.pb.h | ||
kUtils.h | ||
SelectableItem.h | ||
CloudManager.h | ||
SkeletonManager.h | ||
) | ||
|
||
ADD_LIBRARY(${LIB_NAME} | ||
"SHARED" | ||
${PLUGIN_HEADERS} | ||
KinectDemo.cpp | ||
Skeleton.cpp | ||
MCylinder.cpp | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/skeletonframe.pb.cc | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/skeleton.pb.cc | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/colormap.pb.cc | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/depthmap.pb.cc | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/pointcloud.pb.cc | ||
${REMOTEKINECT_INCLUDE_DIR}/protocol/packing.pb.cc | ||
kUtils.cpp | ||
SelectableItem.cpp | ||
CloudManager.cpp | ||
# SkeletonManager.cpp | ||
) | ||
|
||
SET(CMAKE_BUILD_TYPE Release) | ||
|
||
ADD_DEFINITIONS(-std=c++0x -O3) | ||
|
||
|
||
FIND_PACKAGE(Snappy) | ||
FIND_PACKAGE(Protobuf) | ||
FIND_PACKAGE(ZMQ) | ||
FIND_PACKAGE(UUID) | ||
FIND_PACKAGE(RemoteKinect) | ||
|
||
|
||
INCLUDE_DIRECTORIES(${OSG_INCLUDE_DIR}) | ||
INCLUDE_DIRECTORIES(${MXML_INCLUDE_DIR}) | ||
INCLUDE_DIRECTORIES(${SPACENAV_INCLUDE_DIR}) | ||
INCLUDE_DIRECTORIES(${SNAPPY_INCLUDE_DIR}) | ||
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) | ||
INCLUDE_DIRECTORIES(${ZMQ_INCLUDE_DIR}) | ||
INCLUDE_DIRECTORIES(${REMOTEKINECT_INCLUDE_DIR}) | ||
INCLUDE_DIRECTORIES(${CalVR_Plugins_SOURCE_DIR}/calit2/KinectDemo/) | ||
|
||
TARGET_LINK_LIBRARIES(${LIB_NAME} ${OSG_LIBRARIES}) | ||
TARGET_LINK_LIBRARIES(${LIB_NAME} ${MXML_LIBRARY}) | ||
TARGET_LINK_LIBRARIES(${LIB_NAME} ${SNAPPY_LIBRARY}) | ||
TARGET_LINK_LIBRARIES(${LIB_NAME} ${PROTOBUF_LIBRARY}) | ||
TARGET_LINK_LIBRARIES(${LIB_NAME} ${ZMQ_LIBRARY}) | ||
TARGET_LINK_LIBRARIES(${LIB_NAME} ${UUID_LIBRARY}) | ||
TARGET_LINK_LIBRARIES(${LIB_NAME} ${SPACENAV_LIBRARY}) | ||
TARGET_LINK_LIBRARIES(${LIB_NAME} ${VRPN_LIBRARY}) | ||
|
||
|
||
ADD_CALVR_LIBRARIES(${LIB_NAME}) | ||
|
||
INSTALL(TARGETS ${LIB_NAME} DESTINATION lib/plugins) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
#include "CloudManager.h" | ||
|
||
#include <cvrKernel/ComController.h> | ||
#include <sstream> | ||
#include <algorithm> | ||
#include <cstdio> | ||
|
||
#include <sys/syscall.h> | ||
#include <sys/stat.h> | ||
|
||
using namespace cvr; | ||
using namespace std; | ||
|
||
CloudManager::CloudManager() | ||
{ | ||
useKColor = true; | ||
should_quit = false; | ||
|
||
//initialPointScale = 0.001; | ||
initialPointScale = ConfigManager::getFloat("Plugin.KinectDemo.KinectDefaultOn.KinectPointSize",0.0f); | ||
pgm1 = new osg::Program; | ||
pgm1->setName("Sphere"); | ||
std::string shaderPath = ConfigManager::getEntry("Plugin.Points.ShaderPath"); | ||
pgm1->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, osgDB::findDataFile(shaderPath + "/Sphere.vert"))); | ||
pgm1->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, osgDB::findDataFile(shaderPath + "/Sphere.frag"))); | ||
pgm1->addShader(osg::Shader::readShaderFile(osg::Shader::GEOMETRY, osgDB::findDataFile(shaderPath + "/Sphere.geom"))); | ||
pgm1->setParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 4); | ||
pgm1->setParameter(GL_GEOMETRY_INPUT_TYPE_EXT, GL_POINTS); | ||
pgm1->setParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP); | ||
minDistHSV = 700; | ||
maxDistHSV = 5000; | ||
|
||
kinectgrp = new osg::Group(); | ||
osg::StateSet* state = kinectgrp->getOrCreateStateSet(); | ||
state->setAttribute(pgm1); | ||
state->addUniform(new osg::Uniform("pointScale", initialPointScale)); | ||
state->addUniform(new osg::Uniform("globalAlpha", 1.0f)); | ||
float pscale = 1.0; | ||
osg::Uniform* _scaleUni = new osg::Uniform("pointScale", 1.0f * pscale); | ||
kinectgrp->getOrCreateStateSet()->addUniform(_scaleUni); | ||
|
||
_root = new osg::MatrixTransform(); | ||
SceneManager::instance()->getObjectsRoot()->addChild(_root); | ||
_root->addChild(kinectgrp); | ||
|
||
} | ||
|
||
CloudManager::~CloudManager() | ||
{ | ||
} | ||
|
||
bool CloudManager::isCacheDone() | ||
{ | ||
return _cacheDone; | ||
} | ||
|
||
void CloudManager::update() | ||
{ | ||
static bool frameLoading = false; | ||
bool cDone; | ||
if(true) | ||
{ | ||
if(cvr::ComController::instance()->isMaster()) | ||
{ | ||
cDone = _cacheDone; | ||
int numSlaves = cvr::ComController::instance()->getNumSlaves(); | ||
bool sDone[numSlaves]; | ||
cvr::ComController::instance()->readSlaves(sDone,sizeof(bool)); | ||
for(int i = 0; i < numSlaves; i++) | ||
{ | ||
cDone = cDone && sDone[i]; | ||
} | ||
cvr::ComController::instance()->sendSlaves(&cDone,sizeof(bool)); | ||
} | ||
else | ||
{ | ||
cDone = _cacheDone; | ||
cvr::ComController::instance()->sendMaster(&cDone,sizeof(bool)); | ||
cvr::ComController::instance()->readMaster(&cDone,sizeof(bool)); | ||
} | ||
|
||
if(!cDone) | ||
{ | ||
//std::cerr << "Waiting for load to finish." << std::endl; | ||
return; | ||
} | ||
|
||
cvr::ComController::instance()->sync(); | ||
//Add not here? | ||
|
||
|
||
return; | ||
} | ||
if(cDone) | ||
{ | ||
std::cerr << "Load Finished." << std::endl; | ||
//Add loaded node to root | ||
|
||
} | ||
else | ||
{ | ||
// std::cerr << "Waiting for GPU load finish." << std::endl; | ||
} | ||
|
||
} | ||
|
||
void CloudManager::run() | ||
{ | ||
//Do functions | ||
cerr << "."; | ||
if(kinectgrp != NULL) | ||
{ | ||
|
||
zmq::context_t context2(1); | ||
cloudT_socket = NULL; | ||
cloudT_socket = new SubSocket<RemoteKinect::PointCloud> (context2, ConfigManager::getEntry("Plugin.KinectDemo.KinectServer.PointCloud")); | ||
|
||
packet = new RemoteKinect::PointCloud(); | ||
while(!should_quit) | ||
{ | ||
|
||
//printf("."); | ||
if(cloudT_socket != NULL) | ||
{ | ||
// printf("NotNull"); | ||
|
||
if (cloudT_socket->recv(*packet)) | ||
{ | ||
float r, g, b, a; | ||
osg::Vec3Array* kinectVertices = new osg::Vec3Array; | ||
// kinectVertices->empty(); | ||
osg::Vec3Array* normals = new osg::Vec3Array; | ||
osg::Vec4Array* kinectColours = new osg::Vec4Array; | ||
// kinectColours->empty(); | ||
// cerr << "."; | ||
//int size = packet->points_size(); | ||
//printf("Points %i\n",size); | ||
if(true) | ||
{ | ||
for (int i = 0; i < packet->points_size(); i++) | ||
{ | ||
/* | ||
osg::Vec3f ppos((packet->points(i).x() / 1000) + Skeleton::camPos.x(), | ||
(packet->points(i).z() / -1000) + Skeleton::camPos.y(), | ||
(packet->points(i).y() / 1000) + Skeleton::camPos.z()); | ||
*/ | ||
osg::Vec3f ppos((packet->points(i).x() / 1000), | ||
(packet->points(i).z() / -1000), | ||
(packet->points(i).y() / 1000)); | ||
kinectVertices->push_back(ppos); | ||
//useKColor | ||
if (useKColor) | ||
{ | ||
r = (packet->points(i).r() / 255.); | ||
g = (packet->points(i).g() / 255.); | ||
b = (packet->points(i).b() / 255.); | ||
a = 1; | ||
kinectColours->push_back(osg::Vec4f(r, g, b, a)); | ||
} | ||
else | ||
{ | ||
kinectColours->push_back(getColorRGB(packet->points(i).z())); | ||
} | ||
} | ||
//cerr << kinectVertices->size(); | ||
|
||
osg::Geode* kgeode = new osg::Geode(); | ||
kgeode->setCullingActive(false); | ||
osg::Geometry* nodeGeom = new osg::Geometry(); | ||
osg::StateSet* state = nodeGeom->getOrCreateStateSet(); | ||
nodeGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, kinectVertices->size())); | ||
osg::VertexBufferObject* vboP = nodeGeom->getOrCreateVertexBufferObject(); | ||
vboP->setUsage(GL_STREAM_DRAW); | ||
nodeGeom->setUseDisplayList(true); | ||
nodeGeom->setUseVertexBufferObjects(true); | ||
nodeGeom->setVertexArray(kinectVertices); | ||
nodeGeom->setColorArray(kinectColours); | ||
nodeGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); | ||
kgeode->addDrawable(nodeGeom); | ||
kgeode->dirtyBound(); | ||
//if (kinectgrp != NULL) _root->removeChild(kinectgrp); | ||
kinectgrp->removeChild(0, 1); | ||
kinectgrp->addChild(kgeode); | ||
|
||
|
||
} | ||
} | ||
if(should_quit) | ||
{ | ||
pgm1->ref(); | ||
kinectgrp->removeChild(0, 1); | ||
_root->removeChild(kinectgrp); | ||
kinectgrp = NULL; | ||
|
||
} | ||
} | ||
} | ||
} | ||
//When Finished | ||
_cacheDone = true; | ||
|
||
|
||
|
||
|
||
std::cerr << "All frames loaded." << std::endl; | ||
|
||
} | ||
|
||
void CloudManager::quit() | ||
{ | ||
|
||
should_quit = true; | ||
// pgm1->ref(); | ||
// kinectgrp->removeChild(0, 1); | ||
// _root->removeChild(kinectgrp); | ||
// kinectgrp = NULL; | ||
|
||
} | ||
|
||
osg::Vec4f CloudManager::getColorRGB(int dist) | ||
{ | ||
if (distanceColorMap.count(dist) == 0) // that can be commented out after precomputing completely if the range of Z is known (and it is set on the server side) | ||
{ | ||
float r, g, b; | ||
float h = depth_to_hue(minDistHSV, dist, maxDistHSV); | ||
HSVtoRGB(&r, &g, &b, h, 1, 1); | ||
distanceColorMap[dist] = osg::Vec4f(r, g, b, 1); | ||
} | ||
|
||
return distanceColorMap[dist]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//#ifndef _ANIMATION_MANAGER_MULT | ||
//#define _ANIMATION_MANAGER_MULT | ||
|
||
#include <osgDB/ReadFile> | ||
#include <osgDB/FileUtils> | ||
#include <cvrKernel/SceneManager.h> | ||
#include <cvrConfig/ConfigManager.h> | ||
#include <cvrKernel/PluginHelper.h> | ||
#include <cvrKernel/CVRPlugin.h> | ||
#include <cvrMenu/MenuCheckbox.h> | ||
#include <cvrMenu/MenuButton.h> | ||
#include <cvrMenu/MenuRangeValue.h> | ||
|
||
#include <shared/PubSub.h> | ||
#include <protocol/skeletonframe.pb.h> | ||
#include <protocol/colormap.pb.h> | ||
#include <protocol/depthmap.pb.h> | ||
#include <protocol/pointcloud.pb.h> | ||
#include <zmq.hpp> | ||
#include "kUtils.h" | ||
//#include "Skeleton.h" | ||
#include <unordered_map> | ||
|
||
|
||
#include <iostream> | ||
#include <string> | ||
#include <map> | ||
|
||
#include <OpenThreads/Thread> | ||
|
||
|
||
// zmq::context_t contextCloud(1); | ||
|
||
class CloudManager : public OpenThreads::Thread { | ||
|
||
public: | ||
|
||
CloudManager(); | ||
~CloudManager(); | ||
//contextCloud(1); | ||
SubSocket<RemoteKinect::PointCloud>* cloudT_socket; | ||
void update(); | ||
bool isCacheDone(); | ||
RemoteKinect::PointCloud* packet; | ||
|
||
virtual void run(); | ||
void quit(); | ||
protected: | ||
|
||
// osg::ref_ptr<osg::Vec4Array> kinectColours; | ||
// osg::ref_ptr<osg::Vec3Array> kinectVertices; | ||
bool _cacheDone; | ||
bool useKColor; | ||
bool should_quit; | ||
osg::Program* pgm1; | ||
osg::Group* kinectgrp; | ||
osg::MatrixTransform* _root; | ||
float initialPointScale; | ||
int minDistHSV, maxDistHSV; | ||
int minDistHSVDepth, maxDistHSVDepth; | ||
std::unordered_map<float, osg::Vec4f> distanceColorMap; | ||
osg::Vec4f getColorRGB(int dist); | ||
float distanceMIN, distanceMAX; | ||
float _sphereRadius; | ||
}; | ||
|
||
//#endif |
Oops, something went wrong.