Frequently Asked Questions during development
How to handle several components within only one component extension
You have created a component extension MyComponentExtension
with
several components : MyComponent1
, MyComponent2
. The CamiTK wizard
asks you to select only one top level component.
It is strongly advised to have only one top level by component extension. The top-level component is instantiated in when opening a file corresponding to the managed extension.
How to manage data without a file
In CamiTK, Component are used to manage all the data. The manage a specific type of data you have to consider whether it is a generic type of data, a type of mesh or a type of image (and coming soon: a type of video camera, a type of pointer etc…). If your data type can be assimilate to static data, i.e., it can be instanciate/initialize from data coming from a file, the only thing you have to do is to create a new Component extension and in the extension class, just declare which file extension is used to load your data from a file.
However, sometimes you data are coming on the fly, or are acquired
directly from a device or are “programmatically” generated (e.g., using
a vtkSource
class), without having any initial static file to open.
In this case, there are two ways to load data in CamiTK without having to use any data file to start with:
- create an initializer action, or
- define a specific file type / model of the connection to your device (name, parameters of the connection, etc…)
How to create an initializer action
This action is not specific to any component, i.e., that will be available at any time, even when no component are in memory. In this case you can trigger the action at any time in the Action menu of camitk-imp. This action should :
- initialize the connection to a device, and
- create an empty specific camitk::Component or initialize this component from the connection
The action
- can have parameters that will be taken into account when the “apply” button is clicked (see SphereTopology in sdk/actions/mesh/basictopology for an example)
- can have no parameters, in this case the apply() method is run immediately when the action is triggered (see CloseAction in sdk/actions/application)
How to define a specific file type
This can help you generalize an acquisition device idea. You can define a specific component, e.g. FooComponent that would generalized the concept of FooDevice and have some parameters like name, connection parameters etc… define in a text/xml file. Then, you create a specific action for FooComponent to start the acquisition (or whatever you need to do to initialize the data or change it on the fly).
How to make Save As work on a Component which is neither an Image nor a Mesh
To use the “Save As…” action, CamiTK looks for the extension which creates your Component. If your SpecialComponent inherits from ImageComponent or MeshComponent, it will find any Component Extension saving an Image or a Mesh. However, if your SpecialComponent directly inherits from Component, the only way it has to find the appropriate Save method (in your Special Component Extension) is to look at the file extension of your SpecialComponent. So as soon as you create an instance of your SpecialComponent, you must give it a file name (using setFileName()), even if the corresponding file does not exist (e.g. if your created your SpecialComponent instance thanks to an action) with the proper extension so that “Save As…” action can find your SpecialComponentExtension to save it.
How to add a new class to a CamiTK project
You have added a class in your CamiTK project, and when compiling it, the class is forgotten by your IDE (no compilation). Simply run CMake on your project to consider it. Once done, when recompiling your project, your class will be now examinated.
How to detect modifications in Component explorer (or another viewer)
As far as you work with several components, it could be interesting to catch some signals to hide or delete some objects you created in an action for one of the component to avoid unexpected behaviors.
Let us take a pratical example like developing an interactive vtkSeedWidget action in the viewers for an imageComponent. If you don`t catch signals, your seeds will stay in the viewers after the deletion of your component and finally it will crash because events in vtk pipeline will lost for your seeds. To manage this, you can use two signals which are selectionChanged() (provided by CamiTK) and destroyed(QObject*) (provided by Qt). The first one is sed to manage a change in viewers or explorer. With our example, it can be used to hide or screen our seeds. The second one is use to catch the deletion of your component. Here, the aim will be to delete seeds to free the memory. In the constructor, you can connect these methods with dedicated methods in your code.
// manage the slots
if (!isConnected) {
QObject::connect(Explorer::getInstance(), SIGNAL(selectionChanged()), this, SLOT(XX()));
QObject::connect(MyImgComponent, SIGNAL(destroyed(QObject*)), this, SLOT(YY(QObject*)));
isConnected = true;
}
Don`t forget to also manage the disconnection of these methods.
How to create an action of actions
In the case you want use a series of CamiTK actions in one of your action before your algorithm, you should set to false the flag that inform your image has been modified. To do that, perform an action in your action, change the flag to false and perform your algorithm.
ImageComponent * input = dynamic_cast<ImageComponent *> (performLaplacianSharpeningAction(comp));
input->setModified(false);
myAlgo (input->getImageData());
How to display point and cell data in camitk-imp
To test the expected behaviour, lets use the “plate-with-data.vtk” example file that came with the feature (it originally comes from the VTK data test suite and contains well scaled vectors relatively to the data).
Display the "Data" tab in the Property Explorer, it should list all the loaded data attached to the point, the cell or global mesh. Data can be either scalars, 3D vectors or 9D tensors.
3D representation of scalar and 9D tensors can be activated by clicking on the checkbox on the left corresponding to the data.
3D Representation of vector data can be done simultaneously, with a 3D vector (arrows, unscaled arrows or hedge hog representation) and as a colour corresponding either to magnitude (norm), 1st, 2nd or 3rd component of the vector. The colour representation can only be one of these four choices.
Choosing a specific vector data representation, use the two combo boxes at the bottom of the "Data" tab:
- the first one on the left let you choose the representation of your vector data (it does not do anything for scalar or tensor data)
- the second one on the left let you choose specific ways of rendering 3D vectors (arrows, unscaled arrows which does not use the data magnitude to scale the representation and hedge hog which uses simple lines instead of arrows).
Therefore:
- To show the vector data as 3D vectors, set the first combo box on the left to "3D Vector", select the 3D vector representation to either arrows, unscaled arrows or hedge hog and tick the checkbox on the vector data of your choice.
- To show the vector data as colours, set the first combo box to either norm, 1st, 2nd or 3rd component and then tick the checkbox on the vector data of your choice.
Changing the first combo box will let you see which representation is active (the checkbox is ticked for the corresponding active representation). Only one colour representation is possible at a time, but both one colour representation and 3D vectors are possible together.
The vector data can be set either on the cell field or on the point field:
- if set on the cell field, then the arrows are centred on the cell and the cell is coloured with the corresponding colour (no interpolation between the points)
- if set on the point field, then the arrows starts at the vertex and the color is attributed to the vertex (resulting in an interpolation along the cells’ surface)
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.