PaintBehavior.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2016, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_GRAPHICS_PAINTBEHAVIOR_H
#define SURGSIM_GRAPHICS_PAINTBEHAVIOR_H
#include "SurgSim/Collision/Representation.h"
#include "SurgSim/DataStructures/IndexedLocalCoordinate.h"
#include "SurgSim/Framework/Behavior.h"
#include "SurgSim/Framework/Component.h"
#include "SurgSim/Framework/Logger.h"
#include "SurgSim/Graphics/OsgMeshRepresentation.h"
#include "SurgSim/Graphics/OsgTexture2d.h"
#include "SurgSim/Math/Matrix.h"
#include "SurgSim/Math/Vector.h"
namespace SurgSim
{
namespace Graphics
{
SURGSIM_STATIC_REGISTRATION(PaintBehavior);
class PaintBehavior : public Framework::Behavior
{
public:
explicit PaintBehavior(const std::string& name);
SURGSIM_CLASSNAME(SurgSim::Graphics::PaintBehavior);
void setRepresentation(std::shared_ptr<Framework::Component> representation);
std::shared_ptr<Graphics::OsgMeshRepresentation> getRepresentation() const;
void setTextureSize(int width, int height);
void setColor(const Math::Vector4d& color);
Math::Vector4d getColor() const;
void setRadius(double radius);
double getRadius() const;
void setAntiAlias(bool antialias);
bool getAntiAlias() const;
void setCoordinates(const std::vector<DataStructures::IndexedLocalCoordinate>& coordinate);
bool doInitialize() override;
bool doWakeUp() override;
void update(double dt) override;
private:
void buildBrush(double radius);
void buildAntiAliasedBrush(double radius);
Math::Vector2d toPixel(const Math::Vector2d& uv);
void paint(const Math::Vector2d& coordinates);
std::shared_ptr<Graphics::OsgMeshRepresentation> m_representation;
std::shared_ptr<Graphics::OsgTexture2d> m_texture;
Math::Vector4d m_color;
int m_width;
int m_height;
double m_radius;
bool m_antialias;
std::vector<DataStructures::IndexedLocalCoordinate> m_coordinates;
int m_brushOffsetX;
int m_brushOffsetY;
Math::Matrix m_brush;
boost::mutex m_mutex;
};
} // Graphics
} // SurgSim
#endif // SURGSIM_GRAPHICS_PAINTBEHAVIOR_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::PaintBehavior::setRepresentation
void setRepresentation(std::shared_ptr< Framework::Component > representation)
Sets graphics representation being painted on.
Definition: PaintBehavior.cpp:44
SurgSim::Graphics::PaintBehavior::m_radius
double m_radius
Radius of brush.
Definition: PaintBehavior.h:120
SurgSim::Graphics::PaintBehavior::m_color
Math::Vector4d m_color
Color to use for decal painting.
Definition: PaintBehavior.h:111
SurgSim::Graphics::PaintBehavior::m_brushOffsetY
int m_brushOffsetY
Definition: PaintBehavior.h:129
SurgSim::Graphics::PaintBehavior::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: PaintBehavior.cpp:132
SurgSim::Graphics::PaintBehavior::update
void update(double dt) override
Update the behavior.
Definition: PaintBehavior.cpp:167
SurgSim::Math::Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
Component.h
SurgSim::Graphics::PaintBehavior::setRadius
void setRadius(double radius)
Sets radius of paint splat.
Definition: PaintBehavior.cpp:199
IndexedLocalCoordinate.h
SurgSim::Graphics::PaintBehavior::setCoordinates
void setCoordinates(const std::vector< DataStructures::IndexedLocalCoordinate > &coordinate)
Sets collection of local triangle coordinates to paint on during next update.
Definition: PaintBehavior.cpp:83
SurgSim::Graphics::PaintBehavior::m_texture
std::shared_ptr< Graphics::OsgTexture2d > m_texture
Image data of the texture to be used as the decal layer.
Definition: PaintBehavior.h:108
SurgSim::Graphics::PaintBehavior::m_height
int m_height
Height of assigned texture.
Definition: PaintBehavior.h:117
SurgSim::Graphics::PaintBehavior::m_mutex
boost::mutex m_mutex
Definition: PaintBehavior.h:133
SurgSim::Graphics::PaintBehavior::PaintBehavior
PaintBehavior(const std::string &name)
Definition: PaintBehavior.cpp:31
SurgSim::Graphics::PaintBehavior::buildBrush
void buildBrush(double radius)
Builds paint brush at the set radius size.
Definition: PaintBehavior.cpp:209
SurgSim::Graphics::PaintBehavior::setTextureSize
void setTextureSize(int width, int height)
Sets the size of the texture layer to paint onto.
Definition: PaintBehavior.cpp:89
Behavior.h
SurgSim::Graphics::PaintBehavior::m_coordinates
std::vector< DataStructures::IndexedLocalCoordinate > m_coordinates
Collection of UV texture coordinates to paint to on next update.
Definition: PaintBehavior.h:126
SurgSim::Graphics::PaintBehavior::m_brush
Math::Matrix m_brush
Definition: PaintBehavior.h:131
SurgSim::Graphics::PaintBehavior::getRadius
double getRadius() const
Gets radius of paint splat.
Definition: PaintBehavior.cpp:204
Representation.h
SurgSim::Graphics::PaintBehavior::m_brushOffsetX
int m_brushOffsetX
Definition: PaintBehavior.h:128
SurgSim::Graphics::PaintBehavior::m_representation
std::shared_ptr< Graphics::OsgMeshRepresentation > m_representation
Graphics representation of the mesh to apply behavior to.
Definition: PaintBehavior.h:105
SurgSim::Graphics::PaintBehavior::getRepresentation
std::shared_ptr< Graphics::OsgMeshRepresentation > getRepresentation() const
Gets graphics representation being painted on.
Definition: PaintBehavior.cpp:50
Matrix.h
Definitions of small fixed-size square matrix types.
SurgSim::Graphics::PaintBehavior::paint
void paint(const Math::Vector2d &coordinates)
Apply paint brush to texture at specified texture coordinates.
Definition: PaintBehavior.cpp:291
SurgSim::Math::Vector2d
Eigen::Matrix< double, 2, 1 > Vector2d
A 2D vector of doubles.
Definition: Vector.h:53
OsgTexture2d.h
SurgSim::Graphics::PaintBehavior::buildAntiAliasedBrush
void buildAntiAliasedBrush(double radius)
Builds an antialiased brush at the set radius size.
Definition: PaintBehavior.cpp:239
Vector.h
Definitions of small fixed-size vector types.
SurgSim::Graphics::PaintBehavior::m_antialias
bool m_antialias
Flag for antialiasing the brush.
Definition: PaintBehavior.h:123
Logger.h
SurgSim::Framework::Behavior
Behaviors perform actions.
Definition: Behavior.h:40
SurgSim::Graphics::PaintBehavior::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::PaintBehavior)
SurgSim::Graphics::PaintBehavior::setAntiAlias
void setAntiAlias(bool antialias)
Sets whether to anti-alias the brush.
Definition: PaintBehavior.cpp:65
SurgSim::Graphics::PaintBehavior::getAntiAlias
bool getAntiAlias() const
Gets status of antialiased brush.
Definition: PaintBehavior.cpp:78
OsgMeshRepresentation.h
SurgSim::Graphics::PaintBehavior::setColor
void setColor(const Math::Vector4d &color)
Sets color of the paint.
Definition: PaintBehavior.cpp:55
SurgSim::Graphics::PaintBehavior::getColor
Math::Vector4d getColor() const
Gets color of the paint.
Definition: PaintBehavior.cpp:60
SurgSim::Graphics::PaintBehavior
Behavior class to allow a specified scene element to receive painting effects.
Definition: PaintBehavior.h:37
SurgSim::Graphics::PaintBehavior::m_width
int m_width
Width of assigned texture.
Definition: PaintBehavior.h:114
SurgSim::Math::Vector4d
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
SurgSim::Graphics::PaintBehavior::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: PaintBehavior.cpp:103
SurgSim::Graphics::PaintBehavior::toPixel
Math::Vector2d toPixel(const Math::Vector2d &uv)
Convert texture uv coordinates to pixel coordinates.
Definition: PaintBehavior.cpp:277