AIS_TexturedShape

I am user AIS_TexturedShape map image it ok~
but the image map after the color become Yellow .
How to change the color ?

Thank you for any help ...

eric ro

mbd_forever's picture

Hi Eric,

What code do you use to change color ?

mbd_forever

Eric Ro's picture

I don't know change color.
I am user AIS_TexturedShape this dictation map a image the image have show up, but
the image inclination yellow

Thereinafter is my code.

Handle(V3d_Viewer) myViewer = myCurrentIC->CurrentViewer();
myViewer->InitActiveViews();
myViewer->SetLightOn();
Handle(V3d_View) myView = myViewer->ActiveView();
myView->FitAll(0.01,Standard_True);
myView->SetSurfaceDetail(V3d_TEX_ALL);

myCurrentIC->InitCurrent();
Handle(AIS_InteractiveObject) curAISObject = myCurrentIC->Current();
TopoDS_Shape aShape = myCurrentIC->SelectedShape();
Handle_AIS_TexturedShape aTShape = new AIS_TexturedShape(aShape);
TCollection_AsciiString aFile(aFileName);
aTShape->SetTextureFileName(aFile);
aTShape->SetTextureMapOn();
//aTShape->SetTextureRepeat(FALSE,2.5,8);

aTShape->SetTextureRepeat(FALSE,2.5,8);
aTShape->SetTextureScale(TRUE,1,2);
aTShape->SetDisplayMode(3); ;
myCurrentIC->Display(aTShape);
myCurrentIC->UpdateCurrentViewer();
aTShape->UpdateAttributes();

mbd_forever's picture

Hi Eric,

The problem I see in your code is when you set attributes of the image map (SetTextureRepeat and SetTextureScale) :
If the first argument is 'False', you don't need to set the other arguments. Change 'False' with 'True' in aTShape->SetTextureRepeat(FALSE,2.5,8);

You will get a better result!

If you don't repeat texture, a part of the face receives the textures and the rest of the face receives the last column of pixels of the texture. This is due to an OpenGL specification.

I guess you would have preferred to avoid this last column of pixels ...

The shape is yellow because texture colors are mixed with the default color of the face (yellow) and with your application default lights.

To see how everything works, try to change the color of the shape before applying the texture, try to add some lights with differents colors, and then try to map a texture which last columns of pixels contains non-blank pixels, you will see that this column is repeated.

mbd_forever

Eric Ro's picture

I try change the coloe of the shape but impressional not change.
I a find a question.
when i user AIS_Trihedron the map image can't manifest the image will become black .

Thereinafter is my code.

Handle(AIS_Trihedron) aTrihedron;
Handle(Geom_Axis2Placement) aTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
aTrihedron=new AIS_Trihedron(aTrihedronAxis);
aTrihedron->UnsetSize();
myAISContext->Display(aTrihedron);
myAISContext->Deactivate(aTrihedron);

eric ro

j-lin's picture

How do you map image?
Can you post your code?

Andreas Hussong's picture

The following code allows you to map images on surfaces:

void CMove3Doc::OnTexture()
{
myAISContext->InitSelected();
if (myAISContext->HasSelectedShape()){
TopoDS_Shape myAISShape = myAISContext->SelectedShape();
AIS_TexturedShape *thetexshape = new AIS_TexturedShape(myAISShape);
CFileDialog dlg(TRUE, "bmp", "*.bmp");
if (dlg.DoModal() == IDOK){
CString C = dlg.GetPathName();
Standard_CString aFileName = (Standard_CString)(LPCTSTR)C;
TCollection_AsciiString theTexFile(aFileName);
thetexshape->SetTextureFileName(theTexFile);
thetexshape->SetTextureMapOn();
thetexshape->SetDisplayMode(3);
myAISContext->Display(thetexshape);
myAISContext->UpdateCurrentViewer();
thetexshape->UpdateAttributes();
}
}
else {
AfxMessageBox("No Surface selected.");
}
for(;myAISContext->MoreCurrent();myAISContext->NextCurrent())
myAISContext->SetDisplayMode(myAISContext->Current(),3);
}

A surface must be selected . To change the Selection-Mode use

myAISContext->OpenLocalContext();
myAISContext->ActivateStandardMode(TopAbs_FACE);

Don't forget to set
myView->SetSurfaceDetail(V3d_TEX_ALL);
to see the textures. I did this in OnInitialUpdate of the View-Class.

Hope this helps.

Andreas

mbd_forever's picture

Hi Andreas !

I think there's a problem in your code ...

What happens when you close the local context (go back to neutral point) ?

When you close it, I think you loose the presentation of your shape, don't you ?

mbd_forever

Andreas Hussong's picture

Yes I do...
that's one of my problems at the moment.
But I wasn't able to change the collection mode to TopAbs_FACE in neutral point. That's why I need to do everything in one opened local context.

Andreas

mbd_forever's picture

AIS_TexturedShape was designed to map an image on ALL faces of a shape.

If you want to map a texture on 'only some faces', I think the only possibility is to subclass AIS_TexturedShape and to add a 'setfacestomap' method.

Then in the 'Compute' method of AIS_TexturedShape, you only map the texture on this set of faces ... and you can shade the others ...

This can be difficult to manage because if you select 10 faces, map a texture on them, and then want to add and map a new face, you have to select all of them one more time !

Good luck and keep us informed !

mbd_forever

Andreas Hussong's picture

The way I do it is quite sufficient for my problem.
Most of the time I do not have too complicated objects. At the moment I select the objects surface face by face and attach special images to every face.
This works quite good with my code, so that I get quite realistic-looking Objects, like a packet of gauloise-cigarettes for example :-)
(which is my testing object at the moment...)

I want to use this data to teach an image-processing system for object recognition...

Andreas