Multiple interaction in 1 RenderWindow - vtk

I have 3 renderers which are shown in 1 Render Window, now I want to pick a point in the first 2 renderer.. So far, the code below only work for src_renderer. What should I do so each renderer has its own interaction?
Thanks..
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(1024, 320);
renderWindow->AddRenderer(src_renderer);
renderWindow->AddRenderer(tar_renderer);
renderWindow->AddRenderer(res_renderer);
// An interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow ( renderWindow );
// Set the custom stype to use for interaction.
vtkSmartPointer<MouseInteractorStyle2> src_style = vtkSmartPointer<MouseInteractorStyle2>::New();
vtkSmartPointer<MouseInteractorStyle2> tar_style = vtkSmartPointer<MouseInteractorStyle2>::New();
src_style->SetDefaultRenderer(src_renderer);
tar_style->SetDefaultRenderer(tar_renderer);
renderWindowInteractor->SetInteractorStyle( src_style );

You can show multiple renderers within a RenderWindow by defining a separate viewport for each renderer, through the method SetViewport. That way, you can interact with each renderer. Have a look at this example, I think it might help you.

you can add an observer to the interactor object to switch interactor styles. see here.

Related

Changing all Shape's colors at once JavaFX

I'm writing a small program in which multiple shapes will be visible in JavaFX. I'm trying to create a button through which it is possible to change all the shape's color to the chosen one by the user.
Right now, I'm only able to do that by changing each shape individually in my lambda expression. It's okay for now since there's only three shapes, but it will be inconvenient further one. Can anyone think of a way to group all the shapes together and access the "setFill" method to change them all at once?
Here's the code:
// Calling Semi-Circle method
Arc semicircle1 = shapes1.getsemicircle();
// create Colors button and set is as invisible until a shape value is passed by user
Button buttonColors = new Button();
buttonColors.setText("Choose a color for the Shape");
buttonColors.setVisible(true);
buttonColors.setOnAction( e ->
{
if (textField1.getText().equalsIgnoreCase("Grey"))
{
label1.setText("Grey");
semicircle1.setFill(Color.GREY);
}
});
You may create some property and bind all shapes to it
final ObjectProperty<Paint> fillProperty = new SimpleObjectProperty(Color.GREY);
...
semicirle1.fillProperty().bind(fillProperty);
pentagon1.fillProperty().bind(fillProperty);
rectangle1.fillProperty().bind(fillProperty);
...
fillProperty.set(Color.RED);

Vaadin 10 Dialog emulating Vaadin 8 Window Caption

Using Vaadin Flow Java API I would like to emulate a Vaadin 8 Window feature: particularly I need to emulate Caption behaviour.
I mean a fixed top "Title" not scrollable as the real content of the Dialog. Anyone can tell me some Example I could learn from ?
Thanks in advance
This is the workaround I found.
public MainView() {
Button button = new Button("Click me",
event -> {
Dialog dialog = new Dialog();
HorizontalLayout horizontalLayout = new HorizontalLayout();
VerticalLayout verticalLayout = new VerticalLayout();
Div headerDiv = new Div();
Div bodyDiv = new Div();
bodyDiv.getElement().getStyle().set("overflow", "auto");
bodyDiv.getElement().getStyle().set("max-height", "420px"); // !!!
dialog.add(headerDiv, bodyDiv);
headerDiv.add(horizontalLayout);
bodyDiv.add(verticalLayout);
horizontalLayout.add(new Label("Hi there !"));
for (int i = 1; i <= 20; i++) {
verticalLayout.add(new TextField("TextField_" + i));
}
dialog.open();
});
add(button);
}
The trouble is that I have to fix max-height size to avoid scrolling of all the contained components. So I cannot take advantage from the auto-size behaviour of the Dialog Container. Also tried using setFlexGrow, but I did not reach the solution.
Any Hint ?
In Vaadin 10+ there is no component called Window, but there is component called Dialog. It does not have Title like Window, but otherwise it has similar baseline. I.e. it is popup. Based on your question you have found already that.
Dialog itself is component container, which means you can add components there. I would just create e.g two Divs (the simplest of the layout components in Vaadin 10). I would style the first one to have fixed height and place the Title there. And then I would apply component.getElement().getStyle().set("overflow", "auto") to the other one, which is the actual content body. The mentioned style will enable the scrollable feature. You could potentially use VerticalLayout / HorizontalLayout instead of Div as well depending what you need.
See also: https://vaadin.com/docs/v10/flow/migration/5-components.html

Adding nested stackviews programmatically using xamarin.ios c#

I am creating a app for both android and ios using xamarin and mvvmcross.
In the ios app I want to add outer vertical stackview having nested horizontal stackviews. Basically I just want to create a basic person details screen where will be Label on left and textfield on right which will go in one horizontal stackview and like this there will many horizontal stackviews nested in outer vertical stackview.
I am looking for such example on internet but seems most of the examples are in swift but I was hardly able to find some in c#.
Can someone please help.
Thanks,
Santosh
UIStackView leverages the power of Auto Layout and Size Classes to manage a stack of subviews, either horizontally or vertically, which dynamically responds to the orientation and screen size of the iOS device. You can learn about it through this documentation.
In your case, we can construct a vertical stack to place several horizontal stack:
UIStackView verticalStack = new UIStackView();
View.AddSubview(verticalStack);
verticalStack.Axis = UILayoutConstraintAxis.Vertical;
verticalStack.TranslatesAutoresizingMaskIntoConstraints = false;
// Use auto layout to embed this super vertical stack in the View. Also there's no need to set the height constraint, vertical stack will automatically adjust that depending on its content
verticalStack.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor).Active = true;
verticalStack.TopAnchor.ConstraintEqualTo(TopLayoutGuide.GetBottomAnchor()).Active = true;
verticalStack.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor).Active = true;
for (int i=0; i<10; i++)
{
// Here try to put some horizontal stack with Label on left and textfield on right in the father stack.
UIStackView horizontalStack = new UIStackView();
horizontalStack.Distribution = UIStackViewDistribution.EqualSpacing;
horizontalStack.Axis = UILayoutConstraintAxis.Horizontal;
// UIStackView should use AddArrangedSubview() to add subviews.
verticalStack.AddArrangedSubview(horizontalStack);
UILabel textLabel = new UILabel();
textLabel.Text = "text";
UITextField textField = new UITextField();
textField.Placeholder = "enter text";
horizontalStack.AddArrangedSubview(textLabel);
horizontalStack.AddArrangedSubview(textField);
}
But if every horizontal stack's subViews are almost the same style and layouts. Why not try to use UITableView? You just need to set the single cell's contents and layouts, then use it in the tableView. Moreover this control is reused and scrollable.

Knowing renderer which I click it

I have a render window where I spread 4 renderers ... how can I know on which of them I made click ? I have seen some examples of how to know the object on I made click, not renderer ...
Thank you.
It should be possible to get the clicked renderer through the interactor of the renderwindow.
e.g.
int x = myRenderWindow->GetInteractor()->GetEventPosition()[0];
int y = myRenderWindow->GetInteractor()->GetEventPosition()[1];
vtkRenderer myPokedRenderer = myRenderWindow->GetInteractor()->FindPokedRenderer(x, y);

three.js - mesh group example? (THREE.Object3D() advanced)

I'm attempting to understand how to group / link child meshes to a parent. I want to be able to:
drag the parent
rotate child elements relative to the parent
have parent rotation / translation do the right thing for children
My only background in this is using LSL in Second Life to manipulate linked prims in an object. I am thinking I dont want to merge meshes, because I want to maintain control (hover, texture, rotation, scaling, etc) over each child.
Any good tutorials on this out there? This is achieved with THREE.Object3D(), yes?
thanks, Daniel
The dragging will be a bit more tricky because you need to work out where would the x/y positions of the mouse on the screen (screen space) will be in the 3D world, then you will need to cast a ray and check if it intersects the object you want to drag. I presume this will be a different question.
Setting object hierarchy is fairly simple.
As you hinted, you will use a THREE.Object3D instance to nest objects into using it's add() method. The idea is that you will use a Mesh for objects that have geometry, and Object3D instances, where you simply need to nest elements.
group = new THREE.Object3D();//create an empty container
group.add( mesh );//add a mesh with geometry to it
scene.add( group );//when done, add the group to the scene
Update
As Nick Desaulniers and escapedcat point out, THREE.Group now provides the functionality you need. The included code example:
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
const cubeA = new THREE.Mesh( geometry, material );
cubeA.position.set( 100, 100, 0 );
const cubeB = new THREE.Mesh( geometry, material );
cubeB.position.set( -100, -100, 0 );
//create a group and add the two cubes
//These cubes can now be rotated / scaled etc as a group
const group = new THREE.Group();
group.add( cubeA );
group.add( cubeB );
scene.add( group );
another way, because a mesh can be a parent too
meshParent.add(meshChild1);
meshParent.add(meshChild2);
scene.add(meshParent);
or
mesh1.add(mesh2);
mesh3.add(mesh1);
scene.add(mesh3);
mesh3 manipulates all meshes, mesh1 manipulates itself and mesh2, mesh2 manipulates itself

Resources