[vtkusers] InteractionProp in Java
Jim Peterson
jimcp at cox.net
Sat Nov 13 17:02:30 EST 2010
Ambar,
In my opinion, you have a solution that worked in C++, extend the
function of the class in C++ which makes protected attributes available
to your code. You are expecting extending the java wrapper to that C++
class to behave the same. You are correct, the protected variable
InteractionProp is not accessible directly from Java because the JCI
exposes the get/set functions and other public functions of the class,
the fact is no attributes of the C++ classes are available as attributes
of the corresponding Java classes. My best understanding of JNI is no
attributes of the native classes are available by direct reference, the
only access to attributes is via get/set functions, and InteractionProp
is protected in vtk and therefore not exposed.
It could be you have an argument for providing a getInteractionProperty
from the interactionStyle classes, but I would say it needs to be
justified by something other than "it is not accessible".
The bottom line is you apparently have a C++ class that implements what
you want. If you want to code an interface change in Java you need to
start from what you want and chose a solution that is available, like an
addObserver callback or an interaction using display of vtk from Java.
Maybe this discussion would be more productive if you describe what you
want to do in terms of changing the interaction behavior and not how you
think you should be able to do it.
Hope that helps,
Jim
Ambar C wrote:
> Hello,
>
> I understand the way JNI works in VTK, but the member that I'm having
> trouble accessing isn't something that I've overloaded any C++ class
> with. I'm trying to be able to access the InteractionProp member of
> the vtkInteractorStyleTrackballActor, which is a protected member
> object of the class. My observation so far is that this member doesn't
> seem to be recognized in the Java wrapped implementation. I'm not sure
> how JNI would tie into this lack of propagation, but do correct me if
> I'm wrong.
>
> Cheers,
> Ambar
>
> On Sat, Nov 13, 2010 at 10:37 AM, Jim Peterson <jimcp at cox.net> wrote:
>
>> Ambar,
>> The set of vtk classes available in Java are not actually java classes, they
>> are interfaces with the C++ vtk classes implemented in the vtk shared
>> libraries. The Java terminology is the classes are implemented via the Java
>> Native Interface (JNI). As such, you cannot extend vtk classes in Java to
>> add functionality as you might in C++. The vtk C++ logic is unaware of the
>> Java extensions.
>> You have at least three choices are:
>> 1. Add your modified C++ class to vtk so that it is included in one of the
>> vtk shared libraries and wrapped by the Java interface and available to your
>> Java program.
>> 2. Use the mouse move or other interaction callbacks in your java code to
>> gain control and interact with your vtk model.
>> 3. Use the relatively undocumented vtkRenderWindowPanel class from Java so
>> that you can use Java UI events to interact with the vtk object.
>>
>> I am not exactly sure what your eventual goal is other that the interaction
>> modifications, but some examples of the java addObserver callbacks and Swing
>> panel implementation are available from here:
>> http://www.vtk.org/Wiki/VTK/Examples/Java
>>
>> Hope that helps,
>> Jim
>>
>> Ambar C wrote:
>>
>>> Hi Jim,
>>>
>>> Could you be more specific? What would I need to do to be able to grab
>>> the mouse driven value changes in orientation and position in Java? I
>>> don't understand how I'd be able to replace the interaction prop's
>>> functionality. Thanks for the help.
>>>
>>> Best,
>>> Ambar
>>>
>>> On Tue, Nov 9, 2010 at 4:04 AM, Jim Peterson <jimcp at cox.net> wrote:
>>>
>>>
>>>> Ambar C wrote:
>>>>
>>>>
>>>>> Hello,
>>>>>
>>>>> I'm working on modifying an vtkInteractorStyleTrackballActor to have
>>>>> my own custom class, and am trying to access it's InteractionProp
>>>>> member but it doesn't seem to be coming through. The equivalent code
>>>>> works in C++, but something along the lines of
>>>>>
>>>>> public modifiedClass extends vtkInteractorStyleTrackballActor
>>>>> {
>>>>> .....
>>>>> this.InteractionProp. //Doesn't recognize the member.
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>> Ambar,
>>>> I think this is not a valid construct for classes that are used for JNI
>>>> interfaces. Yes, Java compiles it, but no, there is no runtime
>>>> inheritance
>>>> to the c++ classes. The pure java way to modify interaction behavior is
>>>> to
>>>> use the interaction observers. If you want to use your C++ code you would
>>>> need to add it to the vtk source tree and rebuild both vtk and the java
>>>> wrappers, The new class can be wrapped and accessible to Java in that
>>>> way.
>>>>
>>>> If you need to address this completely in Java, maybe it would be better
>>>> to
>>>> identify your desired modification to the interaction rather than the
>>>> solution first.
>>>>
>>>> Hope that helps,
>>>> Jim
>>>>
>>>>
>>>>
>>>
>>
>
>
More information about the vtkusers
mailing list