Displaying a TopoDS_Shape

Hi everyone,

I am trying to display to display a shape using:

myAISContext->Display(sh);

where sh is a shape of type TopoDS_Shape. I get the error message - "error C2065: 'myAISContext' : undeclared identifier".

Could someone please tell me what headers I need to include for this to work? (I have included AIS_TexturedShape.hxx, AIS_Shape.hxx & AIS.hxx)

Thanks in advance!!

Patrik Mueller's picture

Hi,

how about:

#include

Greets,

Patrik

Karthik Viswanathan's picture

Hi Patrik,

I added #include to my code, but I still get the same error. Do you or anybody else have any ideas on what I am doing wrong?

Thanks again !!

Patrik Mueller's picture

Hi,

do you have really declared "myAISContext"?

Karthik Viswanathan's picture

Patrik,

I tried declaring it as:

Handle(AIS_TexturedShape) myAISContext;
myAISContext->Display(sh);

Now I get an error saying - "error C2039: 'Display' : is not a member of 'AIS_TexturedShape'". Could you please tell me the correct way to declare it?

Thanks !

Karthik Viswanathan's picture

Forgot to mention - Handle(AIS_InteractiveContext) myAISContext; does not work either

Patrik Mueller's picture

Hi,

can you show us your declarations?

Karthik Viswanathan's picture

Hi Patrick,

Here is a part of my code:

IGESControl_Reader myIgesReader;
Standard_Integer nIgesFaces,nTransFaces;
myIgesReader.ReadFile ("circ_hole_XY1.igs");
//loads the IGES file
Handle(TColStd_HSequenceOfTransient) myList = myIgesReader.GiveList("iges-faces");
//selects all IGES faces in the file and puts them into a list called //MyList,
nIgesFaces = myList->Length();
nTransFaces = myIgesReader.TransferList(myList);
//translates MyList,
cout<<"IGES Faces: "<Display(sh);

The headers that I included for using "myAISContext->Display" are:

#include "AIS_TexturedShape.hxx"
#include "AIS_Shape.hxx"
#include "AIS.hxx"
#include "AIS_InteractiveContext.hxx"

Like I said earlier, I also tried "Handle(AIS_InteractiveContext)" instead of "Handle(AIS_TexturedShape)" but it still gives the same error.

Thank you once again !

Patrik Mueller's picture

Hi,

looks a little bit strange - normally you would have something like this for display:

Handle(AIS_TexturedShape) aisShape = new AIS_TexturedShape(sh);
m_pAISContext->Display(aisShape);

with:

TopoDS_Shape sh;
Handle(AIS_InteractiveContext) m_pAISContext;

Karthik Viswanathan's picture

Hi Patrik,

Thanks for your reply. When I tried using your sample code snippet, my program crashes. I get an error - " has encountered a problem and needs to close. We are sorry for the inconvinience."

The program doesnot crash when I remove the line - "m_pAISContext->Display(aisShape);". So, it looks like there is a problem with that line. Do you know what the problem could be? Any other ideas on how to display the shape?

Thanks a bunch !!

Patrik Mueller's picture

Hi,

do you really have a valid AIS_InteractiveContext? You can check it with:

if (!m_pAISContext.IsNull())

Karthik Viswanathan's picture

Hi Patrik,

if (!m_pAISContext.IsNull()) gives me a null value. I used the code sample that you gave me earlier, so could you please tell me what could be wrong? The code that I used is:

TopoDS_Shape sh = myIgesReader.OneShape();
Handle(AIS_InteractiveContext) m_pAISContext;
Handle(AIS_TexturedShape) aisShape = new AIS_TexturedShape(sh);
m_pAISContext->Display(aisShape);

P Dolbey's picture

I've sort of been following this thread, and I'm not sure that I understand what I'me seeing here.

Reading this verbatim, the line

Handle(AIS_InteractiveContext) m_pAISContext;

is defining an interactive context. Now traditionally variable prefixes like m_... or my... indicate that variable is a class member, but here the variable is declared in-line and is not initialised. Somewhere I would have expected to have seen some code like

m_pViewer = new V3d_Viewer (....)
m_pAISContext = new AIS_InteractiveContext( m_pViewer );

to set up the viewers and so on, as you would find in the examples. The code fragment as presented in the previous post would never work like that! I think Patrik has assumed, like me, that previous posts were describing declarations not actual code sequences.

For me to understand more I'd need to see pretty much the entire program source - that's an offer if you want to take it up.

Pete

Karthik Viswanathan's picture

Hi Pete,

Thanks for your reply. Here is a part of my source code:

int main()
{
IGESControl_Reader myIgesReader;
Standard_Integer nIgesFaces,nTransFaces;
myIgesReader.ReadFile ("circ_hole_XY1.igs");
//loads the IGES file
Handle(TColStd_HSequenceOfTransient) myList = myIgesReader.GiveList("iges-faces");
//selects all IGES faces in the file and puts them into a list called //MyList,
nIgesFaces = myList->Length();
nTransFaces = myIgesReader.TransferList(myList);
//translates MyList,
cout<<"IGES Faces: "<

P Dolbey's picture

Before I respond, I need to know a few things.

1. What is your program for - aka what are the requirements?
2. What is your experience level in, say C, C++, MFC, Qt, Win32, Visual Studio, OpenGL?
3. How quickly do you need a result?

Pete

Karthik Viswanathan's picture

Hi Pete,

1. I am writing a program that loads two IGES files, converts them into OCC shapes, gets the dimensions (of the building block and all sub-fearures) of these shapes, compares the corresponding dimensions between the 2 models and calculates the commonality between them using an index that I have developed. I need to display the OCC shapes generated from the two IGES models.

2. I am not a pro in C, C++ programming. I can do simple stuff, but I do not have much experience with class inheritence, pointers etc. I started using VC++ 6.0 only 7 months ago, before which I used Turbo C++ briefly. I have not programmed anything in OpenGL or Qt.

3. I like a result as quickly as possible as I need to finish this project within the next week. I am done with pretty much everything except displaying the shapes.

Thanks once again !

P G's picture

Hello

For 1, u can use the Test Harness environment to display
ur algorithm results.
U need to implement ur own function by extending test harness
See (thug.pdf) in docs folder of OCC installation.

regd
PG

P Dolbey's picture

Given your responses to my earlier question. I was going to suggest the same appraoch as PG. Actually back when I had a training course sometime in the last millenium, most of the training was around using a customised (rather than extended) Test Harness. I tried creating a template for you last night, but I've recompiled OCC from scratch against one of the latest tcl/tk distributions from ActiveState - the Test harness compiles but my runtime environment seems broken. HowevertThis approach should relieve you of actually needing to go anywhere near AIS classes. You'll execute your code via a custom tcl command instead that can run the body of your "main" function .

Pete

Karthik Viswanathan's picture

Hi Pete and PG,

Thank you for your replies. I went through the user's guides for the Test Harness and also for Visualization. The Test Harness guide only explains on how to use Draw using TCL commands. What I really need is for my VC++ program to automatically open a Viewer window and display the TopoDS shape defined in my code. I don't need anything fancy - just a simple display with default settings will do.

I tried using a couple of the example code fragments in the Visualization user's guide, but I was unsuccessful. I am not an experienced programmer and also I have a huge time constraint to complete this project. So, I would really appreciate it if any of you experienced programmers out there could give me the code for displaying the shape, which includes creating the viewer etc.

Any help will be greatly appreciated !!

Karthik Viswanathan's picture

Forgot one more thing:

Pete, when you say using DRAW, my code will be executed via a custom TCL command, which will execute my "main" function, how exact is this done? If I took this approach, will I have to open up the Draw Test Harness on my own, or will my code automaticaly open it and display the shape in it. Having to open Draw manually and displaying the IGES file using the "igesread" command would be just like opening Pro/E or Solidworks manually and displaying it in it. This would not be of much help to me.

Thanks!

Carlos's picture

Hello,

Have you tried to compile and run the samples included on the distribution pack?.

I think that you could use one of them (for example \\samples\standard\mfc\07_Viewer3d\viewer3d.sln) as a template (see for example, code on Viewer3dDoc.cpp). On these samples, a form is created and different kinds of shapes are created and displayed. As you have the complete source code, you can easily modify it to include your shapes.

If you feel more confortable on C# there are also one sample for you.

I'm sorry but I'm not a C++ programmer so I can not help to you to much.

Regards

Karthik Viswanathan's picture

Hi Carlos,

The Viewer3d sample compiles and executes fine for me. But, I am unable to comprehend the large amount of code in the workspace, as I am not an expert in C++. I don't know what parts of the code in the Viewer3d workspace I need to use, since I don't need a lot of what the sample does (like creating a sphere, cylinder etc., zooming in/out, changing the view, erasing objects in the display etc). All I want is a simple display (with just the basic settings) of my TopoDS shape that has already been created. I really hope that somebody out there gives me a sample code for doing this.

Thank you once again.

Carlos's picture

Hello,

I can not give you the sample code for your simple application, but if the sample executes Ok you can for example replace the code on "void CViewer3dDoc::OnOverlappedBox() " on Viewer3Ddoc.cpp (line 196).

In this function the following code appears:

void CViewer3dDoc::OnOverlappedBox()
{
OnBox();
if(myOverlappedBox.IsNull()){
BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);

BRepBuilderAPI_NurbsConvert aNurbsConvert(B.Shape());
TopoDS_Shape aBoxShape2 = aNurbsConvert.Shape();

myOverlappedBox = new AIS_Shape(aBoxShape2);

myAISContext->SetMaterial(myOverlappedBox,Graphic3d_NOM_GOLD);
myAISContext->SetDisplayMode(myOverlappedBox,1);

myAISContext->Display(myOverlappedBox);

I think that if you replace the aBoxShape2 Shape with your shape It will be displayed (include a call to a function that generates your shape for example)
You can also delete the code you do not need. There are also other basic samples supplied by Opencascade that can be used.

Regards,