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();
80 slotAddNoise(o_it->id(), maxNoise);
87 slotAddNoise(
int _objectId,
double _maxNoise)
92 slotAddNoise( mesh, _maxNoise );
98 slotAddNoise( mesh, _maxNoise );
104 slotAddNoise( cloud, _maxNoise );
112 template<
class MeshT >
115 slotAddNoise( MeshT* _mesh,
double _maxNoise )
117 if ( _mesh ==
nullptr )
119 emit log(
LOGERR,
"Unable to get mesh for object" );
123 if (!_mesh->has_face_normals())
125 _mesh->request_face_normals();
126 _mesh->update_face_normals();
129 if (!_mesh->has_vertex_normals())
131 _mesh->request_vertex_normals();
132 _mesh->update_vertex_normals();
135 for (
auto vh : _mesh->vertices())
137 double randomNumber = ( double(rand()) / double(RAND_MAX) * 2.0 - 1.0) * _maxNoise;
138 _mesh->point(vh) = _mesh->point(vh) + _mesh->normal(vh) * randomNumber;
141 _mesh->update_normals();
148 slotAddNoise(
SplatCloud* _splat_cloud,
double _maxNoise )
152 emit log(
LOGERR,
"Error: Splat cloud without positions!" );
158 emit log(
LOGINFO,
"No normals available, adding noise in all directions" );
160 for (
unsigned int i = 0 ; i < _splat_cloud->
numSplats() ; ++i)
164 while (direction.sqrnorm() > 1.0)
166 direction[0] = (((double)rand()) / ((
double)RAND_MAX) - 0.5) * 2.0;
167 direction[1] = (((double)rand()) / ((
double)RAND_MAX) - 0.5) * 2.0;
168 direction[2] = (((double)rand()) / ((
double)RAND_MAX) - 0.5) * 2.0;
171 direction.normalize();
173 double randomNumber = ( double(rand()) / double(RAND_MAX) * 2.0 - 1.0) * _maxNoise;
180 for (
unsigned int i = 0 ; i < _splat_cloud->
numSplats() ; ++i)
182 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.
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.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
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.
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
noiseToolbarWidget * tool_
Widget for Toolbox.