Rotating a model

Technical discussions
Post Reply
Warren
Posts: 7
Joined: Thu Mar 30, 2017 4:33 am

Rotating a model

Post by Warren »

Hello

The model I have is almost 4MB large. When saving this model, I ask to set the mouse pointer to a HourGlass, but it does not respond for some reason. Any idea ? Would be nice since saving takes quite a bit of time for such a large model.

I also extended my rotation and zooming routines to the KernelCad control. Problem is each time I make a rotation, it seems that a copy of the model is made, and memory consumption increases and increases and increases until full. Then I have to stop he app and restart. This happens even with only 1 tooth displayed.

My rotation function appears below.

Code: Select all

	Sub RotateAxKCad(ByRef IDesWin  As Int32,  _

                        ByVal RotX     As Double, _
                        ByVal RotY     As Double, _
                        ByVal RotZ     As Double)

            With ChildWindow(IDesWin)

               Dim Ii         As Int32
               Dim IAxis      As Int32  = -1
               Dim RotAngl    As Double =  0#

               Dim iKCModel   As KernCADnet.IModel     = .m_iModel2
               Dim NumSect    As Int32                 =  iKCModel.GetSectionCount()
               Dim iKCSect    As KernCADnet.ISection   
               Dim iKCFrm     As KernCADnet.IFrame
               Dim LView2     As KernCADnet.IView2

               ' Detect which axis
               If     RotX <> 0 Then
                  IAxis   = 0
                  RotAngl = RotX                '/ Degr
               ElseIf RotY <> 0 Then
                  IAxis   = 1
                  RotAngl = RotY                '/ Degr
               ElseIf RotZ <> 0 Then
                  IAxis   = 2
                  RotAngl = RotZ                '/ Degr
               Else
                  Return
               End If

               ' Rotate all sections
               For Ii = 0 To NumSect - 1
                  iKCSect  =  iKCModel.GetSection(Ii)
                  iKCFrm   =  iKCSect
                  iKCFrm.RotateStd(RotAngl, IAxis)
               Next

               ' Recenter display
               LView2  = .AxKCad.GetView()
               LView2.ResetEx(KernCADnet.EViewReset.eViewResetAll)

               ' Update display
              .AxKCad.UpdateSurface()
               DoEvent()
            End With
        End Sub
I suppose there is another way to do this, as when using the mouse whence there is no change in memory usage. In fact, it would be nice to have access to the functions called by the mouse actions. Are these exposed in anyway ?

Thanks
Warren

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Re: Rotating a model

Post by nickz »

Hi Warren
Just to make sure: There are two meaning to rotation. The first one (to look from the other side) affects only the graphical display. It does not modify anything in the model. You do not have to code anything to do that. Just move the mouse with left button down. What you are coding is the second one - actual moving of the object relative to the global frame and the other objects.

Strange... I do not see anything in your code which would affect memory. The change just modifies 12 numbers already allocated in the section. What does DoEvent() do?

I will create a simplest test so we can talk around it

>I suppose there is another way to do this, as when using the mouse whence
> there is no change in memory usage. In fact, it would be nice to have
> access to the functions called by the mouse actions. Are these exposed in
> anyway ?

Yes. There is "Modify" mode of KC. If you call IViewModal.SetViewMode(1). In this mode clicking on an obejct makes it 'current' and can be moved with the mouse. You can restrict rotation to an axis. You can also restrict translations.

There is Modal sample. Unfortunately VB has missed out. There is C# version. Have a look how it runs from the sample explorer: Switch to "Modify" on the top. Turn on both check boxes. In "Rotation Constraint" select "Around Axis". Clikc on the box in 3D, move the mouse while holding the left button down. The box should rotate relative to the rest of the scene. There are links at
http://www.dynoinsight.com/Help/NET/CS/SampleModal.aspx for more info

Nick

Warren
Posts: 7
Joined: Thu Mar 30, 2017 4:33 am

Re: Rotating a model

Post by Warren »

Hello Nick
I was out on a technical tour for few days, so I reply kinda late.
In my code, DoEvent() is simply a wrapper I wrote for System.Windows.Forms.Application.DoEvents() because I could never remember the long form of it ;-((

For the HourGlass, I also tried the MousePointer control in VB.Net, but even this does not react. Not a big deal, but when saving a big model takes 10 secs., the user is left wondering what is happening.

I developed a series of gestures and keyboard combinations to be able to see and orient things. What I am trying to do now is port these in the KernelCad control such that users do not need to learn something else. It is likely that all 2D windows will remain coded with a Picture Box for the foreseable future, and the 3D models only will be displayed in a KC control.

I particular, the 3 buttons on the menu bar allow either Std, Coarse or Fine rotations about X, Y or Z. They are very useful to orient a display to see, for example, where the tool is touching the target tooth flank and I would not go without them.

Probably that instead of rotating the model with RotateLoc or RotateStd, I could use rotating the view; same for Zooming In or Out rather than Scaling. And same for Panning. So using IView() rather than ITransform(). Or maybe is this not possible ?

While the right-mouse click you offer is nice, I also want to maintain my original way with scroll bars for panning, a bounding box for zooming (which is initiated by the Ctrl key + the Left mouse button), and the 3 above buttons for rotations.

Usually, translating C# code to VB.Net is not too much of an issue since I have an application for this. Some parts may be missing when creating a class, but otherwise things are intelligible. I will look at Modal.

Best regards

nickz
Site Admin
Posts: 236
Joined: Fri Jul 26, 2013 3:58 am

Re: Rotating a model

Post by nickz »

Using view manipulation for rotate/zoom is the preferred way as it is faster and does not take much of resources. It is read-only operation. It does not modify the model. There are many interfaces to manipulate point of view (zoom,pan,rotate): http://www.dynoinsight.com/Help/Interfa ... faces.aspx
There are also a number of samples dedicated to view manipulation. Any questions are welcome
What application do you use to convert from C#? We need to do it on our side soon

Warren
Posts: 7
Joined: Thu Mar 30, 2017 4:33 am

Re: Rotating a model

Post by Warren »

Thanks for the replies. What you suggest is what I am doing. Issue is maintaining the zoomed model centered in the display when I rotate. Everything else is fine.

•To convert from C++, I use Tangible Software Solutions\Free Edition CPlusPlus to VB Converter
•To convert from C#, I use C to VB Conversion
I suggest you Google these.

Warren

Post Reply