Removed remaining dynamic cast type checking in *GLCanvas (for drawing shape contours)

This commit is contained in:
Tats
2013-12-16 01:37:54 -05:00
parent 3f99dbdebf
commit 9962c56ba7
4 changed files with 76 additions and 87 deletions
+4 -45
View File
@@ -82,52 +82,11 @@ void DestinationGLCanvas::doDraw()
MainWindow::getInstance().getMapperByMappingId(mapping->getId())->draw();
}
// Draw the shape.
if (!MainWindow::getInstance().hasCurrentMapping())
return;
Shape* shape = getCurrentShape();
if (shape)
// Draw the controls of current mapping.
if (MainWindow::getInstance().hasCurrentMapping() &&
getCurrentShape() != NULL)
{
glColor4f(0.0f, 0.0f, 0.7f, 1.0f);
if (dynamic_cast<Mesh*>(shape))
{
Mesh* mesh = (Mesh*)shape;
std::vector<Quad> quads = mesh->getQuads();
for (std::vector<Quad>::const_iterator it = quads.begin(); it != quads.end(); ++it)
{
glLineWidth(1);
glBegin (GL_LINE_STRIP);
for (int i = 0; i < it->nVertices()+1; i++)
{
glVertex2f(
it->getVertex(i % it->nVertices()).x,
it->getVertex(i % it->nVertices()).y
);
}
glEnd ();
}
}
else
{
// Destination quad.
// Source quad.
glLineWidth(5);
glBegin (GL_LINE_STRIP);
{
for (int i = 0; i < shape->nVertices()+1; i++)
{
glVertex2f(
shape->getVertex(i % shape->nVertices()).x,
shape->getVertex(i % shape->nVertices()).y
);
}
}
glEnd ();
}
MainWindow::getInstance().getMapperByMappingId(MainWindow::getInstance().getCurrentMappingId())->drawControls();
}
glPopMatrix();
+54 -1
View File
@@ -138,6 +138,40 @@ void TextureMapper::draw()
glDisable(GL_TEXTURE_2D);
}
void TextureMapper::drawInput()
{
}
void TextureMapper::drawControls()
{
drawShapeContour(*outputShape, 3, QColor(0, 0, 255));
}
void TextureMapper::drawInputControls()
{
drawShapeContour(*inputShape, 3, QColor(0, 0, 255));
}
void TextureMapper::drawShapeContour(const Shape& shape, int lineWidth, const QColor& color)
{
QColor rgbColor = color.toRgb();
glColor4f(rgbColor.redF(), rgbColor.greenF(), rgbColor.blueF(), 1.0f);
glLineWidth(lineWidth);
glBegin (GL_LINE_STRIP);
for (int i = 0; i < shape.nVertices()+1; i++)
{
glVertex2f(
shape.getVertex(i % shape.nVertices()).x,
shape.getVertex(i % shape.nVertices()).y
);
}
glEnd();
}
void TextureMapper::_buildShapeProperty(QtProperty* shapeItem, Shape* shape)
{
for (int i=0; i<shape->nVertices(); i++)
@@ -191,7 +225,6 @@ void TriangleTextureMapper::_doDraw()
}
}
glEnd();
}
MeshTextureMapper::MeshTextureMapper(std::tr1::shared_ptr<TextureMapping> mapping)
@@ -227,6 +260,26 @@ void MeshTextureMapper::setValue(QtProperty* property, const QVariant& value)
TextureMapper::setValue(property, value);
}
void MeshTextureMapper::drawControls()
{
std::tr1::shared_ptr<Mesh> outputMesh = std::tr1::static_pointer_cast<Mesh>(outputShape);
std::vector<Quad> outputQuads = outputMesh->getQuads();
for (std::vector<Quad>::const_iterator it = outputQuads.begin(); it != outputQuads.end(); ++it)
{
drawShapeContour(*it, 1, QColor(0, 0, 255));
}
}
void MeshTextureMapper::drawInputControls()
{
std::tr1::shared_ptr<Mesh> inputMesh = std::tr1::static_pointer_cast<Mesh>(inputShape);
std::vector<Quad> inputQuads = inputMesh->getQuads();
for (std::vector<Quad>::const_iterator it = inputQuads.begin(); it != inputQuads.end(); ++it)
{
drawShapeContour(*it, 1, QColor(0, 0, 255));
}
}
void MeshTextureMapper::_doDraw()
{
std::tr1::shared_ptr<Mesh> outputMesh = std::tr1::static_pointer_cast<Mesh>(outputShape);
+10
View File
@@ -72,6 +72,7 @@ public:
virtual QWidget* getPropertiesEditor() = 0;
virtual void draw() = 0;
virtual void drawControls() = 0;
public slots:
virtual void updateShape(Shape* shape)
@@ -94,6 +95,12 @@ public:
virtual QWidget* getPropertiesEditor();
virtual void draw();
virtual void drawInput();
virtual void drawControls();
virtual void drawInputControls();
static void drawShapeContour(const Shape& shape, int lineWidth, const QColor& color);
signals:
void valueChanged();
@@ -148,6 +155,9 @@ public:
MeshTextureMapper(std::tr1::shared_ptr<TextureMapping> mapping);
virtual ~MeshTextureMapper() {}
virtual void drawControls();
virtual void drawInputControls();
public slots:
virtual void setValue(QtProperty* property, const QVariant& value);
+8 -41
View File
@@ -137,49 +137,16 @@ void SourceGLCanvas::doDraw()
std::tr1::shared_ptr<Shape> inputShape = std::tr1::static_pointer_cast<Quad>(textureMapping->getInputShape());
Q_CHECK_PTR(inputShape);
if (it->first == MainWindow::getInstance().getCurrentMappingId())
glColor4f(0.0f, 0.0f, 0.7f, 1.0f);
else
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
if (it->first == MainWindow::getInstance().getCurrentMappingId())
{
Mapper::ptr mapper = MainWindow::getInstance().getMapperByMappingId(it->first);
Q_CHECK_PTR(mapper);
Shape* shape = inputShape.get();
if (dynamic_cast<Mesh*>(shape))
{
Mesh* mesh = (Mesh*)shape;
std::tr1::shared_ptr<TextureMapper> textureMapper = std::tr1::static_pointer_cast<TextureMapper>(mapper);
Q_CHECK_PTR(textureMapper);
std::vector<Quad> quads = mesh->getQuads();
for (std::vector<Quad>::const_iterator it = quads.begin(); it != quads.end(); ++it)
{
glLineWidth(1);
glBegin (GL_LINE_STRIP);
for (int i = 0; i < it->nVertices()+1; i++)
{
glVertex2f(
it->getVertex(i % it->nVertices()).x,
it->getVertex(i % it->nVertices()).y
);
}
glEnd ();
}
}
else
{
// Destination quad.
// Source quad.
glLineWidth(5);
glBegin (GL_LINE_STRIP);
{
for (int i = 0; i < shape->nVertices()+1; i++)
{
glVertex2f(
shape->getVertex(i % shape->nVertices()).x,
shape->getVertex(i % shape->nVertices()).y
);
}
}
glEnd ();
}
textureMapper->drawInputControls();
}
}
glPopMatrix();