43 #include "NoisePlugin.hh" 55 if ( OpenFlipper::Options::gui() ) {
60 connect(
tool_->addNoise, SIGNAL(clicked()),
this, SLOT(slotAddNoise()));
62 QIcon* toolIcon =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"NoiseIcon.png");
64 emit addToolbox( tr(
"Noise") ,
tool_, toolIcon );
76 const double maxNoise =
tool_->maxDistance->value();
81 slotAddNoise(o_it->id(), maxNoise);
88 slotAddNoise(
int _objectId,
double _maxNoise)
93 slotAddNoise( mesh, _maxNoise );
99 slotAddNoise( mesh, _maxNoise );
105 slotAddNoise( cloud, _maxNoise );
113 template<
class MeshT >
116 slotAddNoise( MeshT* _mesh,
double _maxNoise )
118 if ( _mesh ==
nullptr )
120 emit log(
LOGERR,
"Unable to get mesh for object" );
124 if (!_mesh->has_face_normals())
126 _mesh->request_face_normals();
127 _mesh->update_face_normals();
130 if (!_mesh->has_vertex_normals())
132 _mesh->request_vertex_normals();
133 _mesh->update_vertex_normals();
136 for (
auto vh : _mesh->vertices())
138 double randomNumber = ( double(rand()) / double(RAND_MAX) * 2.0 - 1.0) * _maxNoise;
139 _mesh->point(vh) = _mesh->point(vh) + _mesh->normal(vh) * randomNumber;
142 _mesh->update_normals();
149 slotAddNoise(
SplatCloud* _splat_cloud,
double _maxNoise )
153 emit log(
LOGERR,
"Error: Splat cloud without positions!" );
159 emit log(
LOGINFO,
"No normals available, adding noise in all directions" );
161 for (
unsigned int i = 0 ; i < _splat_cloud->
numSplats() ; ++i)
165 while (direction.sqrnorm() > 1.0)
167 direction[0] = (((double)rand()) / ((
double)RAND_MAX) - 0.5) * 2.0;
168 direction[1] = (((double)rand()) / ((
double)RAND_MAX) - 0.5) * 2.0;
169 direction[2] = (((double)rand()) / ((
double)RAND_MAX) - 0.5) * 2.0;
172 direction.normalize();
174 double randomNumber = ( double(rand()) / double(RAND_MAX) * 2.0 - 1.0) * _maxNoise;
181 for (
unsigned int i = 0 ; i < _splat_cloud->
numSplats() ; ++i)
183 double randomNumber = ( double(rand()) / double(RAND_MAX) * 2.0 - 1.0) * _maxNoise;
Position & positions(int _idx)
Get a reference of the predefined property's value.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
unsigned int numSplats() const
Get the number of splats.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
bool hasPositions() const
Return the availability of the predefined property.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Normal & normals(int _idx)
Get a reference of the predefined property's value.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.
bool hasNormals() const
Return the availability of the predefined property.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
noiseToolbarWidget * tool_
Widget for Toolbox.