60 #include "TypeSplatCloud.hh" 62 #include <OpenFlipper/common/BackupData.hh> 64 #include "SplatCloudBackup.hh" 71 static const char SPLATCLOUD_OBJECT_ID_DATANAME[] =
"SplatCloudObjectId";
73 static const double MIN_CLUSTER_BRIGHTNESS = 0.25;
78 TypeSplatCloudPlugin::TypeSplatCloudPlugin() {
81 void TypeSplatCloudPlugin::slotViewChanged()
95 int left, bottom, width, height;
98 float x = (float) left;
99 float y = (float) bottom;
100 float w = (float) width;
101 float h = (float) height;
105 GLfloat depthRange[2];
106 glGetFloatv( GL_DEPTH_RANGE, depthRange );
107 float z = (float) depthRange[0];
108 float d = (float) depthRange[1] - z;
111 if( w<=0.0f || h<=0.0f || d<=0.0f )
116 invVPs[0] = 2.0f / w;
117 invVPs[1] = 2.0f / h;
118 invVPs[2] = 2.0f / d;
123 invVPt[0] = - ( x * invVPs[0] + 1.0f );
124 invVPt[1] = - ( y * invVPs[1] + 1.0f );
125 invVPt[2] = - ( z * invVPs[2] + 1.0f );
129 GLfloat VPs_z = 0.5f * d;
130 GLfloat VPt_z = z + VPs_z;
133 static const double RCP_3 = 1.0 / 3.0;
135 double detMV = mv(0,0) * (mv(1,1)*mv(2,2) - mv(1,2)*mv(2,1))
136 + mv(0,1) * (mv(1,2)*mv(2,0) - mv(1,0)*mv(2,2))
137 + mv(0,2) * (mv(1,0)*mv(2,1) - mv(1,1)*mv(2,0));
138 GLfloat MVs = (GLfloat) pow( fabs( detMV ), RCP_3 );
141 GLfloat VPsFov_y = glstate.
projection()(1,1) * (0.5f * h);
161 splatsShader->
setUniform(
"invViewportScale", invVPs );
162 splatsShader->
setUniform(
"invViewportTransp", invVPt );
163 splatsShader->
setUniform(
"viewportScale_z", VPs_z );
164 splatsShader->
setUniform(
"viewportTransp_z", VPt_z );
165 splatsShader->
setUniform(
"modelviewScale", MVs );
166 splatsShader->
setUniform(
"viewportScaleFov_y", VPsFov_y );
170 if( splatsPickShader )
172 splatsPickShader->
use();
173 splatsPickShader->
setUniform(
"invViewportScale", invVPs );
174 splatsPickShader->
setUniform(
"invViewportTransp", invVPt );
175 splatsPickShader->
setUniform(
"viewportScale_z", VPs_z );
176 splatsPickShader->
setUniform(
"viewportTransp_z", VPt_z );
177 splatsPickShader->
setUniform(
"modelviewScale", MVs );
178 splatsPickShader->
setUniform(
"viewportScaleFov_y", VPsFov_y );
185 dotsShader->
setUniform(
"modelviewScale", MVs );
186 dotsShader->
setUniform(
"viewportScaleFov_y", VPsFov_y );
192 dotsPickShader->
use();
193 dotsPickShader->
setUniform(
"modelviewScale", MVs );
194 dotsPickShader->
setUniform(
"viewportScaleFov_y", VPsFov_y );
204 void TypeSplatCloudPlugin::slotObjectPropertiesChanged(
int _objectId )
212 if( (parent != 0) && parent->
isGroup() )
224 void TypeSplatCloudPlugin::slotObjectUpdated(
int _objectId,
const UpdateType &_updateType )
233 if( splatCloudObject != 0 )
239 addCameraObjects ( splatCloudObject );
240 addClusterObjects( splatCloudObject );
249 void TypeSplatCloudPlugin::objectDeleted(
int _objectId )
258 if( splatCloudObject != 0 )
261 freeCameraObjects ( splatCloudObject );
262 freeClusterObjects( splatCloudObject );
267 if( cameraObject != 0 )
270 eraseCamera( cameraObject );
278 bool TypeSplatCloudPlugin::registerType()
302 object->target(
true);
307 object->target(
true);
311 object->target(
true);
314 QString
name = QString(tr(
"New Splat Cloud %1.spl").arg( object->
id() ));
318 object->setName( f.fileName() );
321 const QColor color = OpenFlipper::Options::defaultColor();
322 const ACG::Vec4f default_color(color.redF(), color.greenF(), color.blueF(), color.alphaF());
323 object->materialNode()->set_color(default_color);
329 emit emptyObjectAdded( object->
id() );
340 if( _objectId == -1 )
348 if( splatCloudObject )
355 backupData =
dynamic_cast<BackupData *
>(
object->objectData( OBJECT_BACKUPS ) );
361 object->setObjectData( OBJECT_BACKUPS, backupData );
375 void TypeSplatCloudPlugin::ungroupGroupObject(
GroupObject *_groupObject )
382 for( i = _groupObject->
childCount() - 1; i >= 0; --i )
392 emit deleteObject( _groupObject->
id() );
402 SplatCloud_Cameras::const_iterator cameraIter;
403 for( cameraIter = _cameraManager.cameras_.begin(); cameraIter != _cameraManager.cameras_.end(); ++cameraIter )
413 if( (parent != 0) && parent->
isGroup() && (parent->
parent() != 0) )
417 if( groupObject != 0 )
444 GroupObject *groupObject = getCamerasGroupObject( _cameraManager );
445 if( groupObject != 0 )
448 ungroupGroupObject( groupObject );
459 GroupObject *groupObject = getClustersGroupObject( _clusterManager );
460 if( groupObject != 0 )
463 ungroupGroupObject( groupObject );
474 ungroupCameraObjects( _cameraManager );
482 objectIDs.reserve( _cameraManager.cameras_.size() );
485 SplatCloud_Cameras::const_iterator cameraIter;
486 for( cameraIter = _cameraManager.cameras_.begin(); cameraIter != _cameraManager.cameras_.end(); ++cameraIter )
491 if( camera.objectId_ != -1 )
494 objectIDs.push_back( camera.objectId_ );
499 RPC::callFunction(
"datacontrol",
"groupObjects", objectIDs, QString(
"Cameras" ) );
510 ungroupClusterObjects( _clusterManager );
517 void TypeSplatCloudPlugin::addCameraObjects(
SplatCloudObject *_splatCloudObject )
521 if( splatCloud == 0 )
526 if( cameraManagerProp == 0 )
533 SplatCloud_Cameras &cameras = cameraManager.cameras_;
534 if( cameras.empty() )
538 int splatCloudObjectId = _splatCloudObject->
id();
543 OpenFlipper::Options::blockSceneGraphUpdates();
546 SplatCloud_Cameras::iterator cameraIter;
547 for( cameraIter = cameras.begin(); cameraIter != cameras.end(); ++cameraIter )
552 if( camera.objectId_ == -1 )
553 emit addEmptyObject(
DATA_CAMERA, camera.objectId_ );
556 if( camera.objectId_ != -1 )
563 cameraObject->
setName( camera.imagePath_.c_str() );
566 cameraObject->
setObjectData( SPLATCLOUD_OBJECT_ID_DATANAME,
new IntPerObjectData( splatCloudObjectId ) );
570 if( cameraNode != 0 )
576 matrix(0,0) = proj.r_[0][0]; matrix(0,1) = proj.r_[1][0]; matrix(0,2) = proj.r_[2][0];
577 matrix(1,0) = proj.r_[0][1]; matrix(1,1) = proj.r_[1][1]; matrix(1,2) = proj.r_[2][1];
578 matrix(2,0) = proj.r_[0][2]; matrix(2,1) = proj.r_[1][2]; matrix(2,2) = proj.r_[2][2];
579 matrix(0,3) = -(proj.r_[0][0]*proj.t_[0] + proj.r_[1][0]*proj.t_[1] + proj.r_[2][0]*proj.t_[2]);
580 matrix(1,3) = -(proj.r_[0][1]*proj.t_[0] + proj.r_[1][1]*proj.t_[1] + proj.r_[2][1]*proj.t_[2]);
581 matrix(2,3) = -(proj.r_[0][2]*proj.t_[0] + proj.r_[1][2]*proj.t_[1] + proj.r_[2][2]*proj.t_[2]);
582 matrix(3,0) = 0.0; matrix(3,1) = 0.0; matrix(3,2) = 0.0; matrix(3,3) = 1.0;
586 unsigned int width = camera.imageWidth_;
587 unsigned int height = camera.imageHeight_;
588 if( (width == 0) || (height == 0) )
596 cameraNode->
setSize( width, height );
609 emit deleteObject( camera.objectId_ );
610 camera.objectId_ = -1;
615 OpenFlipper::Options::unblockSceneGraphUpdates();
618 groupCameraObjects( cameraManager );
627 void TypeSplatCloudPlugin::addClusterObjects(
SplatCloudObject *_splatCloudObject )
631 if( splatCloud == 0 )
636 if( clusterManagerProp == 0 )
643 SplatCloud_Clusters &clusters = clusterManager.clusters_;
644 if( clusters.empty() )
648 int splatCloudObjectId = _splatCloudObject->
id();
653 if( clusterManager.objectId_ == -1 )
657 if( clusterManager.objectId_ != -1 )
664 meshObject->
setName(
"Clusters" );
667 meshObject->
setObjectData( SPLATCLOUD_OBJECT_ID_DATANAME,
new IntPerObjectData( splatCloudObjectId ) );
674 mesh->request_vertex_colors();
675 mesh->request_face_colors();
681 SplatCloud_Clusters::const_iterator clusterIter;
682 for( clusterIter = clusters.begin(); clusterIter != clusters.end(); ++clusterIter )
689 static const double MIN_SQR_BRIGHTNESS = MIN_CLUSTER_BRIGHTNESS * MIN_CLUSTER_BRIGHTNESS;
690 static const double RCP_RAND_MAX = 1.0 / (double) RAND_MAX;
691 static const double RCP_3 = 1.0 / 3.0;
694 double sqrBrightness;
697 r = rand() * RCP_RAND_MAX;
698 g = rand() * RCP_RAND_MAX;
699 b = rand() * RCP_RAND_MAX;
700 sqrBrightness = RCP_3 * (r*r + g*g + b*b);
702 while( sqrBrightness < MIN_SQR_BRIGHTNESS );
708 const ACG::Vec3d &qv0 = cluster.quad_.vertices_[0];
709 const ACG::Vec3d &qv1 = cluster.quad_.vertices_[1];
710 const ACG::Vec3d &qv2 = cluster.quad_.vertices_[2];
711 const ACG::Vec3d &qv3 = cluster.quad_.vertices_[3];
714 std::vector<PolyMesh::VertexHandle> vertexHandles( 4 );
719 mesh->set_color( vertexHandles[0], color );
720 mesh->set_color( vertexHandles[1], color );
721 mesh->set_color( vertexHandles[2], color );
722 mesh->set_color( vertexHandles[3], color );
725 PolyMesh::FaceHandle faceHandle = mesh->add_face( vertexHandles );
726 mesh->set_color( faceHandle, color );
730 mesh->request_face_normals();
731 mesh->request_vertex_normals();
738 groupClusterObjects( clusterManager );
748 emit deleteObject( clusterManager.objectId_ );
749 clusterManager.objectId_ = -1;
759 void TypeSplatCloudPlugin::freeCameraObjects(
SplatCloudObject *_splatCloudObject )
763 if( splatCloud == 0 )
768 if( cameraManagerProp == 0 )
775 SplatCloud_Cameras &cameras = cameraManager.cameras_;
776 if( cameras.empty() )
782 SplatCloud_Cameras::const_iterator cameraIter;
783 for( cameraIter = cameras.begin(); cameraIter != cameras.end(); ++cameraIter )
801 void TypeSplatCloudPlugin::freeClusterObjects(
SplatCloudObject *_splatCloudObject )
805 if( splatCloud == 0 )
810 if( clusterManagerProp == 0 )
833 void TypeSplatCloudPlugin::eraseCamera(
CameraObject *_cameraObject )
836 IntPerObjectData *splatCloudObjectIdPOD =
dynamic_cast<IntPerObjectData *
>( _cameraObject->
objectData( SPLATCLOUD_OBJECT_ID_DATANAME ) );
837 if( splatCloudObjectIdPOD == 0 )
847 if( splatCloud == 0 )
851 int cameraObjectId = _cameraObject->
id();
857 if( cameraManagerProp != 0 )
863 SplatCloud_Cameras &cameras = cameraManager.cameras_;
866 SplatCloud_Cameras::iterator cameraIter;
867 for( cameraIter = cameras.begin(); cameraIter != cameras.end(); ++cameraIter )
870 if( cameraIter->objectId_ == cameraObjectId )
873 cameras.erase( cameraIter );
885 unsigned int splatIdx, numSplats = splatCloud->
numSplats();
886 for( splatIdx = 0; splatIdx < numSplats; ++splatIdx )
889 SplatCloud::Viewlist &viewlist = splatCloud->
viewlists( splatIdx );
892 SplatCloud::Viewlist::iterator viewIter;
893 for( viewIter = viewlist.begin(); viewIter != viewlist.end(); ++viewIter )
896 if( viewIter->cameraObjectId_ == cameraObjectId )
899 viewlist.erase( viewIter );
913 #if QT_VERSION < 0x050000
GLSL::PtrProgram getShader(DrawModes::DrawMode _drawmode, bool _pick=false)
Get the shader for the given drawMode.
const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased)
Add a custom DrawMode.
SplatCloudObject * splatCloudObject(BaseObjectData *_object)
Cast an SplatCloudObject to a SplatCloudObject if possible.
virtual void updatedObject(int _objectId)
An object has been changed or added by this plugin.
QString name()
Return a name for the plugin.
CloudPropertyT< T > * getCloudProperty(const PropertyHandleT< T > &_handle)
Get a pointer to a property.
ACG::GLState & glState()
Get the glState of the Viewer.
int addEmpty()
Create an empty object.
void update_normals()
Compute normals for all primitives.
bool getObject(int _identifier, BSplineCurveObject *&_object)
ShaderNode * splatShaderNode(BaseObjectData *_object)
Get a ShaderNode from an object.
int childCount() const
get the number of children
bool hasViewlists() const
Return the availability of the predefined property.
Abstract class that is used to store backups.
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
Kernel::Color Color
Color type.
const QStringList ALL_OBJECTS
Iterable object range.
void use()
Enables the program object for using.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void setParent(BaseObject *_parent)
Set the parent pointer.
DLLEXPORT DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
MeshT * mesh()
return a pointer to the mesh
void setObjectData(QString _dataName, PerObjectData *_data)
void setName(QString _name)
Set the name of the Object.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void setName(QString _name)
Set the name of the Object.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
int objectCount()
Get the number of available objects.
void storeBackup(BaseBackup *_backup)
store a backup
void generateBackup(int _objectId, QString _name, UpdateType _type)
This slot should be implemented in a TypePlugin to generate type specific backups.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
void setModelView(ACG::GLMatrixd _modelView)
set model view matrix
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
unsigned int numSplats() const
Get the number of splats.
bool hasObjectData(QString _dataName)
Checks if object data with given name is available.
BaseObject * child(int row)
return a child
Add colors to mesh item (vertices/faces/edges)
bool isGroup() const
Check if object is a group.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
void setSize(int _w, int _h)
Set viewport size ( This will be used to compute the aspect ratio )
Reference data()
Access the data as reference.
DrawMode NONE
not a valid draw mode
Class that encapsulates a backup.
int targetCount()
Get the number of target objects.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
const GLMatrixd & projection() const
get projection matrix
CameraObject * cameraObject(int _objectId)
Get a CameraObject from an object id if possible.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Type for a Meshobject containing a poly mesh.
CameraNode * cameraNode()
Get the scenegraph Node.
const GLMatrixd & modelview() const
get modelview matrix
Kernel::Point Point
Coordinate type.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void get_viewport(int &_left, int &_bottom, int &_width, int &_height) const
get viewport
const UpdateType UPDATE_STATE(UpdateTypeSet(1)<< 12)
State has changed.
void clearObjectData(QString _dataName)
Clear the object data pointer ( this will not delete the object!! )
void disable()
Resets to standard rendering pipeline.
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Viewlist & viewlists(int _idx)
Get a reference of the predefined property's value.
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.