54 #include "TypeSplatCloud.hh" 56 #include <OpenFlipper/common/BackupData.hh> 58 #include "SplatCloudBackup.hh" 65 static const char SPLATCLOUD_OBJECT_ID_DATANAME[] =
"SplatCloudObjectId";
67 static const double MIN_CLUSTER_BRIGHTNESS = 0.25;
72 TypeSplatCloudPlugin::TypeSplatCloudPlugin() {
75 void TypeSplatCloudPlugin::slotViewChanged()
89 int left, bottom, width, height;
92 float x = (float) left;
93 float y = (float) bottom;
94 float w = (float) width;
95 float h = (float) height;
99 GLfloat depthRange[2];
100 glGetFloatv( GL_DEPTH_RANGE, depthRange );
101 float z = (float) depthRange[0];
102 float d = (float) depthRange[1] - z;
105 if( w<=0.0f || h<=0.0f || d<=0.0f )
110 invVPs[0] = 2.0f / w;
111 invVPs[1] = 2.0f / h;
112 invVPs[2] = 2.0f / d;
117 invVPt[0] = - ( x * invVPs[0] + 1.0f );
118 invVPt[1] = - ( y * invVPs[1] + 1.0f );
119 invVPt[2] = - ( z * invVPs[2] + 1.0f );
123 GLfloat VPs_z = 0.5f * d;
124 GLfloat VPt_z = z + VPs_z;
127 static const double RCP_3 = 1.0 / 3.0;
129 double detMV = mv(0,0) * (mv(1,1)*mv(2,2) - mv(1,2)*mv(2,1))
130 + mv(0,1) * (mv(1,2)*mv(2,0) - mv(1,0)*mv(2,2))
131 + mv(0,2) * (mv(1,0)*mv(2,1) - mv(1,1)*mv(2,0));
132 GLfloat MVs = (GLfloat) pow( fabs( detMV ), RCP_3 );
135 GLfloat VPsFov_y = glstate.
projection()(1,1) * (0.5f * h);
155 splatsShader->
setUniform(
"invViewportScale", invVPs );
156 splatsShader->
setUniform(
"invViewportTransp", invVPt );
157 splatsShader->
setUniform(
"viewportScale_z", VPs_z );
158 splatsShader->
setUniform(
"viewportTransp_z", VPt_z );
159 splatsShader->
setUniform(
"modelviewScale", MVs );
160 splatsShader->
setUniform(
"viewportScaleFov_y", VPsFov_y );
164 if( splatsPickShader )
166 splatsPickShader->
use();
167 splatsPickShader->
setUniform(
"invViewportScale", invVPs );
168 splatsPickShader->
setUniform(
"invViewportTransp", invVPt );
169 splatsPickShader->
setUniform(
"viewportScale_z", VPs_z );
170 splatsPickShader->
setUniform(
"viewportTransp_z", VPt_z );
171 splatsPickShader->
setUniform(
"modelviewScale", MVs );
172 splatsPickShader->
setUniform(
"viewportScaleFov_y", VPsFov_y );
179 dotsShader->
setUniform(
"modelviewScale", MVs );
180 dotsShader->
setUniform(
"viewportScaleFov_y", VPsFov_y );
186 dotsPickShader->
use();
187 dotsPickShader->
setUniform(
"modelviewScale", MVs );
188 dotsPickShader->
setUniform(
"viewportScaleFov_y", VPsFov_y );
198 void TypeSplatCloudPlugin::slotObjectPropertiesChanged(
int _objectId )
206 if( (parent != 0) && parent->
isGroup() )
218 void TypeSplatCloudPlugin::slotObjectUpdated(
int _objectId,
const UpdateType &_updateType )
227 if( splatCloudObject != 0 )
233 addCameraObjects ( splatCloudObject );
234 addClusterObjects( splatCloudObject );
243 void TypeSplatCloudPlugin::objectDeleted(
int _objectId )
252 if( splatCloudObject != 0 )
255 freeCameraObjects ( splatCloudObject );
256 freeClusterObjects( splatCloudObject );
261 if( cameraObject != 0 )
264 eraseCamera( cameraObject );
272 bool TypeSplatCloudPlugin::registerType()
296 object->target(
true);
301 object->target(
true);
305 object->target(
true);
308 QString
name = QString(tr(
"New Splat Cloud %1.spl").arg( object->
id() ));
312 object->setName( f.fileName() );
315 const QColor color = OpenFlipper::Options::defaultColor();
316 const ACG::Vec4f default_color(color.redF(), color.greenF(), color.blueF(), color.alphaF());
317 object->materialNode()->set_color(default_color);
323 emit emptyObjectAdded( object->
id() );
334 if( _objectId == -1 )
342 if( splatCloudObject )
349 backupData =
dynamic_cast<BackupData *
>(
object->objectData( OBJECT_BACKUPS ) );
355 object->setObjectData( OBJECT_BACKUPS, backupData );
369 void TypeSplatCloudPlugin::ungroupGroupObject(
GroupObject *_groupObject )
376 for( i = _groupObject->
childCount() - 1; i >= 0; --i )
386 emit deleteObject( _groupObject->
id() );
396 SplatCloud_Cameras::const_iterator cameraIter;
397 for( cameraIter = _cameraManager.cameras_.begin(); cameraIter != _cameraManager.cameras_.end(); ++cameraIter )
407 if( (parent != 0) && parent->
isGroup() && (parent->
parent() != 0) )
411 if( groupObject != 0 )
438 GroupObject *groupObject = getCamerasGroupObject( _cameraManager );
439 if( groupObject != 0 )
442 ungroupGroupObject( groupObject );
453 GroupObject *groupObject = getClustersGroupObject( _clusterManager );
454 if( groupObject != 0 )
457 ungroupGroupObject( groupObject );
468 ungroupCameraObjects( _cameraManager );
476 objectIDs.reserve( _cameraManager.cameras_.size() );
479 SplatCloud_Cameras::const_iterator cameraIter;
480 for( cameraIter = _cameraManager.cameras_.begin(); cameraIter != _cameraManager.cameras_.end(); ++cameraIter )
485 if( camera.objectId_ != -1 )
488 objectIDs.push_back( camera.objectId_ );
493 RPC::callFunction(
"datacontrol",
"groupObjects", objectIDs, QString(
"Cameras" ) );
504 ungroupClusterObjects( _clusterManager );
511 void TypeSplatCloudPlugin::addCameraObjects(
SplatCloudObject *_splatCloudObject )
515 if( splatCloud == 0 )
520 if( cameraManagerProp == 0 )
527 SplatCloud_Cameras &cameras = cameraManager.cameras_;
528 if( cameras.empty() )
532 int splatCloudObjectId = _splatCloudObject->
id();
537 OpenFlipper::Options::blockSceneGraphUpdates();
540 SplatCloud_Cameras::iterator cameraIter;
541 for( cameraIter = cameras.begin(); cameraIter != cameras.end(); ++cameraIter )
546 if( camera.objectId_ == -1 )
547 emit addEmptyObject(
DATA_CAMERA, camera.objectId_ );
550 if( camera.objectId_ != -1 )
557 cameraObject->
setName( camera.imagePath_.c_str() );
560 cameraObject->
setObjectData( SPLATCLOUD_OBJECT_ID_DATANAME,
new IntPerObjectData( splatCloudObjectId ) );
564 if( cameraNode != 0 )
567 unsigned int width = camera.imageWidth_;
568 unsigned int height = camera.imageHeight_;
569 if( (width == 0) || (height == 0) )
579 matrixView(0,0) = proj.r_[0][0]; matrixView(0,1) = proj.r_[1][0]; matrixView(0,2) = proj.r_[2][0];
580 matrixView(1,0) = proj.r_[0][1]; matrixView(1,1) = proj.r_[1][1]; matrixView(1,2) = proj.r_[2][1];
581 matrixView(2,0) = proj.r_[0][2]; matrixView(2,1) = proj.r_[1][2]; matrixView(2,2) = proj.r_[2][2];
582 matrixView(0,3) = -(proj.r_[0][0]*proj.t_[0] + proj.r_[1][0]*proj.t_[1] + proj.r_[2][0]*proj.t_[2]);
583 matrixView(1,3) = -(proj.r_[0][1]*proj.t_[0] + proj.r_[1][1]*proj.t_[1] + proj.r_[2][1]*proj.t_[2]);
584 matrixView(2,3) = -(proj.r_[0][2]*proj.t_[0] + proj.r_[1][2]*proj.t_[1] + proj.r_[2][2]*proj.t_[2]);
585 matrixView(3,0) = 0.0; matrixView(3,1) = 0.0; matrixView(3,2) = 0.0; matrixView(3,3) = 1.0;
588 matrixProj.
perspective(proj.f_,
double(width) /
double(height), proj.k1_, proj.k2_);
606 emit deleteObject( camera.objectId_ );
607 camera.objectId_ = -1;
612 OpenFlipper::Options::unblockSceneGraphUpdates();
615 groupCameraObjects( cameraManager );
624 void TypeSplatCloudPlugin::addClusterObjects(
SplatCloudObject *_splatCloudObject )
628 if( splatCloud == 0 )
633 if( clusterManagerProp == 0 )
640 SplatCloud_Clusters &clusters = clusterManager.clusters_;
641 if( clusters.empty() )
645 int splatCloudObjectId = _splatCloudObject->
id();
650 if( clusterManager.objectId_ == -1 )
654 if( clusterManager.objectId_ != -1 )
661 meshObject->
setName(
"Clusters" );
664 meshObject->
setObjectData( SPLATCLOUD_OBJECT_ID_DATANAME,
new IntPerObjectData( splatCloudObjectId ) );
671 mesh->request_vertex_colors();
672 mesh->request_face_colors();
678 SplatCloud_Clusters::const_iterator clusterIter;
679 for( clusterIter = clusters.begin(); clusterIter != clusters.end(); ++clusterIter )
686 static const double MIN_SQR_BRIGHTNESS = MIN_CLUSTER_BRIGHTNESS * MIN_CLUSTER_BRIGHTNESS;
687 static const double RCP_RAND_MAX = 1.0 / (double) RAND_MAX;
688 static const double RCP_3 = 1.0 / 3.0;
691 double sqrBrightness;
694 r = rand() * RCP_RAND_MAX;
695 g = rand() * RCP_RAND_MAX;
696 b = rand() * RCP_RAND_MAX;
697 sqrBrightness = RCP_3 * (r*r + g*g + b*b);
699 while( sqrBrightness < MIN_SQR_BRIGHTNESS );
705 const ACG::Vec3d &qv0 = cluster.quad_.vertices_[0];
706 const ACG::Vec3d &qv1 = cluster.quad_.vertices_[1];
707 const ACG::Vec3d &qv2 = cluster.quad_.vertices_[2];
708 const ACG::Vec3d &qv3 = cluster.quad_.vertices_[3];
711 std::vector<PolyMesh::VertexHandle> vertexHandles( 4 );
716 mesh->set_color( vertexHandles[0], color );
717 mesh->set_color( vertexHandles[1], color );
718 mesh->set_color( vertexHandles[2], color );
719 mesh->set_color( vertexHandles[3], color );
722 PolyMesh::FaceHandle faceHandle = mesh->add_face( vertexHandles );
723 mesh->set_color( faceHandle, color );
727 mesh->request_face_normals();
728 mesh->request_vertex_normals();
735 groupClusterObjects( clusterManager );
745 emit deleteObject( clusterManager.objectId_ );
746 clusterManager.objectId_ = -1;
756 void TypeSplatCloudPlugin::freeCameraObjects(
SplatCloudObject *_splatCloudObject )
760 if( splatCloud == 0 )
765 if( cameraManagerProp == 0 )
772 SplatCloud_Cameras &cameras = cameraManager.cameras_;
773 if( cameras.empty() )
779 SplatCloud_Cameras::const_iterator cameraIter;
780 for( cameraIter = cameras.begin(); cameraIter != cameras.end(); ++cameraIter )
798 void TypeSplatCloudPlugin::freeClusterObjects(
SplatCloudObject *_splatCloudObject )
802 if( splatCloud == 0 )
807 if( clusterManagerProp == 0 )
830 void TypeSplatCloudPlugin::eraseCamera(
CameraObject *_cameraObject )
833 IntPerObjectData *splatCloudObjectIdPOD =
dynamic_cast<IntPerObjectData *
>( _cameraObject->
objectData( SPLATCLOUD_OBJECT_ID_DATANAME ) );
834 if( splatCloudObjectIdPOD == 0 )
844 if( splatCloud == 0 )
848 int cameraObjectId = _cameraObject->
id();
854 if( cameraManagerProp != 0 )
860 SplatCloud_Cameras &cameras = cameraManager.cameras_;
863 SplatCloud_Cameras::iterator cameraIter;
864 for( cameraIter = cameras.begin(); cameraIter != cameras.end(); ++cameraIter )
867 if( cameraIter->objectId_ == cameraObjectId )
870 cameras.erase( cameraIter );
882 unsigned int splatIdx, numSplats = splatCloud->
numSplats();
883 for( splatIdx = 0; splatIdx < numSplats; ++splatIdx )
886 SplatCloud::Viewlist &viewlist = splatCloud->
viewlists( splatIdx );
889 SplatCloud::Viewlist::iterator viewIter;
890 for( viewIter = viewlist.begin(); viewIter != viewlist.end(); ++viewIter )
893 if( viewIter->cameraObjectId_ == cameraObjectId )
896 viewlist.erase( viewIter );
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
int addEmpty()
Create an empty object.
CloudPropertyT< T > * getCloudProperty(const PropertyHandleT< T > &_handle)
Get a pointer to a property.
bool isGroup() const
Check if object is a group.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
Kernel::Point Point
Coordinate type.
Kernel::Color Color
Color type.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
const GLMatrixd & projection() const
get projection matrix
void setName(QString _name)
Set the name of the Object.
int childCount() const
get the number of children
void disable()
Resets to standard rendering pipeline.
MeshT * mesh()
return a pointer to the mesh
Add colors to mesh item (vertices/faces/edges)
CameraObject * cameraObject(int _objectId)
Get a CameraObject from an object id if possible.
void setModelView(ACG::GLMatrixd _modelView)
set model view matrix
const UpdateType UPDATE_STATE(UpdateTypeSet(1)<< 12)
State has changed.
virtual void updatedObject(int _objectId)
An object has been changed or added by this plugin.
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
const QStringList ALL_OBJECTS
Iterable object range.
void setProjection(ACG::GLMatrixd _projection)
Set projection Matrix ( used to calculate frustum ... )
void clearObjectData(QString _dataName)
Clear the object data pointer ( this will not delete the object!! )
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
std::vector< int > IdList
Standard Type for id Lists used for scripting.
unsigned int numSplats() const
Get the number of splats.
DrawMode NONE
not a valid draw mode
void generateBackup(int _objectId, QString _name, UpdateType _type)
This slot should be implemented in a TypePlugin to generate type specific backups.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased)
Add a custom DrawMode.
GLSL::PtrProgram getShader(DrawModes::DrawMode _drawmode, bool _pick=false)
Get the shader for the given drawMode.
void setObjectData(QString _dataName, PerObjectData *_data)
Abstract class that is used to store backups.
DLLEXPORT DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
void setName(QString _name)
Set the name of the Object.
void storeBackup(BaseBackup *_backup)
store a backup
QString name()
Return a name for the plugin.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
const GLMatrixd & modelview() const
get modelview matrix
void setParent(BaseObject *_parent)
Set the parent pointer.
void perspective(Scalar fovY, Scalar aspect, Scalar near_plane, Scalar far_plane)
multiply self with a perspective projection matrix
Reference data()
Access the data as reference.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void identity()
setup an identity matrix
bool hasObjectData(QString _dataName)
Checks if object data with given name is available.
bool hasViewlists() const
Return the availability of the predefined property.
ACG::GLState & glState()
Get the glState of the Viewer.
CameraNode * cameraNode()
Get the scenegraph Node.
SplatCloudObject * splatCloudObject(BaseObjectData *_object)
Cast an SplatCloudObject to a SplatCloudObject if possible.
Class that encapsulates a backup.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
int objectCount()
Get the number of available objects.
BaseObject * child(int row)
return a child
int targetCount()
Get the number of target objects.
Type for a Meshobject containing a poly mesh.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
void update_normals()
Compute normals for all primitives.
ShaderNode * splatShaderNode(BaseObjectData *_object)
Get a ShaderNode from an object.
void use()
Enables the program object for using.
Viewlist & viewlists(int _idx)
Get a reference of the predefined property's value.