Hi,
Can anyone show me how to render/paint/display an object created by opencascade?
I have a very simple functional piece of opencascade code that creates a 3D cylinder:
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <gp_Ax2.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS.hxx>
#include <AIS_Shape.hxx>
TopoDS_Shape MakeCylinder(const Standard_Real radius , const Standard_Real length)
{
// Create coordinates & geometry
gp_Pnt origin(0 , 0 , 0);
gp_Dir direction = gp::DZ();
gp_Ax2 axis(origin , direction);
// Create a cylinder
BRepPrimAPI_MakeCylinder cylinder(axis , radius , length);
TopoDS_Shape shape = cylinder.Shape();
return shape;
}
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <gp_Ax2.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS.hxx>
#include <AIS_Shape.hxx>
TopoDS_Shape MakeCylinder(const Standard_Real radius , const Standard_Real length)
{
// Create coordinates & geometry
gp_Pnt origin(0 , 0 , 0);
gp_Dir direction = gp::DZ();
gp_Ax2 axis(origin , direction);
// Create a cylinder
BRepPrimAPI_MakeCylinder cylinder(axis , radius , length);
TopoDS_Shape shape = cylinder.Shape();
return shape;
}
To copy to clipboard, switch view to plain text mode
I have created an empty widget application using qtcreator, and that has generated main.cpp, widget.cpp, widget.h, and widget.ui:
foo.jpg
#include <QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
Widget w;
w.show();
return a.exec();
}
#include <QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
and
#include "widget.h"
#include "ui_widget.h"
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
To call my piece of opencascade code I have changed 'Widget' to this:
ui(new Ui::Widget)
{
ui->setupUi(this);
// I added this:
TopoDS_Shape aCylinder = MakeCylinder(50,400);
Handle(AIS_Shape) AISBottle = new AIS_Shape(aCylinder);
// Now what?
}
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
// I added this:
QApplication::setOverrideCursor( Qt::WaitCursor );
TopoDS_Shape aCylinder = MakeCylinder(50,400);
Handle(AIS_Shape) AISBottle = new AIS_Shape(aCylinder);
QApplication::restoreOverrideCursor();
// Now what?
}
To copy to clipboard, switch view to plain text mode
As you can see I still need to display my image somehow? This would appear to be such a simple thing to do, but I am completely new to Qt and opencascade, so the tutorial example at the opencascade website goes totally over my head.
Please can someone help me?
I am currently using Qt Creator version 2.5.0 on Debian. The opencascade version in Debian is based on opencascade 6.5.2, and I think Qt is version 4.8.2.
Many thanks!
Thomas
Bookmarks