-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow3DController.java
2961 lines (2670 loc) · 120 KB
/
Window3DController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Bao Lab 2017
*/
package wormguides.controllers;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import javax.imageio.ImageIO;
import Timeline.TimelineChart;
import javafx.animation.Timeline;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.PerspectiveCamera;
import javafx.scene.SnapshotParameters;
import javafx.scene.SubScene;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeItem;
import javafx.scene.image.WritableImage;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Material;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Cylinder;
import javafx.scene.shape.Line;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.Shape3D;
import javafx.scene.shape.Sphere;
import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale;
import javafx.scene.transform.Transform;
import javafx.scene.transform.Translate;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import acetree.LineageData;
import connectome.Connectome;
import wormguides.layers.SearchLayer;
import wormguides.layers.StoriesLayer;
import wormguides.models.camerageometry.Xform;
import wormguides.models.cellcase.CasesLists;
import wormguides.models.colorrule.Rule;
import wormguides.models.subscenegeometry.SceneElement;
import wormguides.models.subscenegeometry.SceneElementMeshView;
import wormguides.models.subscenegeometry.SceneElementsList;
import wormguides.models.subscenegeometry.StructureTreeNode;
import wormguides.resources.ProductionInfo;
import wormguides.stories.Note;
import wormguides.stories.Note.Display;
import wormguides.util.ColorComparator;
import wormguides.util.ColorHash;
import wormguides.util.subscenesaving.JavaPicture;
import wormguides.util.subscenesaving.JpegImagesToMovie;
import static java.lang.Math.pow;
import static java.lang.Math.round;
import static java.lang.Math.sqrt;
import static java.lang.Thread.sleep;
import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static javafx.application.Platform.runLater;
import static javafx.scene.Cursor.CLOSED_HAND;
import static javafx.scene.Cursor.DEFAULT;
import static javafx.scene.Cursor.HAND;
import static javafx.scene.input.MouseButton.PRIMARY;
import static javafx.scene.input.MouseButton.SECONDARY;
import static javafx.scene.input.MouseEvent.MOUSE_CLICKED;
import static javafx.scene.input.MouseEvent.MOUSE_DRAGGED;
import static javafx.scene.input.MouseEvent.MOUSE_ENTERED;
import static javafx.scene.input.MouseEvent.MOUSE_ENTERED_TARGET;
import static javafx.scene.input.MouseEvent.MOUSE_MOVED;
import static javafx.scene.input.MouseEvent.MOUSE_PRESSED;
import static javafx.scene.input.MouseEvent.MOUSE_RELEASED;
import static javafx.scene.input.ScrollEvent.SCROLL;
import static javafx.scene.layout.AnchorPane.setRightAnchor;
import static javafx.scene.layout.AnchorPane.setTopAnchor;
import static javafx.scene.paint.Color.RED;
import static javafx.scene.paint.Color.WHITE;
import static javafx.scene.paint.Color.web;
import static javafx.scene.text.FontSmoothingType.LCD;
import static javafx.scene.transform.Rotate.X_AXIS;
import static javafx.scene.transform.Rotate.Y_AXIS;
import static javafx.scene.transform.Rotate.Z_AXIS;
import static com.sun.javafx.scene.CameraHelper.project;
import static javax.imageio.ImageIO.write;
import static partslist.PartsList.getFunctionalNameByLineageName;
import static partslist.PartsList.getLineageNamesByFunctionalName;
import static partslist.PartsList.isFunctionalName;
import static search.SearchType.LINEAGE;
import static search.SearchType.NEIGHBOR;
import static search.SearchUtil.getFirstOccurenceOf;
import static search.SearchUtil.getLastOccurenceOf;
import static wormguides.models.colorrule.SearchOption.CELL_BODY;
import static wormguides.models.colorrule.SearchOption.CELL_NUCLEUS;
import static wormguides.stories.Note.Display.CALLOUT_LOWER_LEFT;
import static wormguides.stories.Note.Display.CALLOUT_LOWER_RIGHT;
import static wormguides.stories.Note.Display.CALLOUT_UPPER_LEFT;
import static wormguides.stories.Note.Display.CALLOUT_UPPER_RIGHT;
import static wormguides.stories.Note.Display.OVERLAY;
import static wormguides.stories.Note.Display.SPRITE;
import static wormguides.util.AppFont.getBillboardFont;
import static wormguides.util.AppFont.getOrientationIndicatorFont;
import static wormguides.util.AppFont.getSpriteAndOverlayFont;
import static wormguides.util.subsceneparameters.Parameters.getBillboardScale;
import static wormguides.util.subsceneparameters.Parameters.getCameraFarClip;
import static wormguides.util.subsceneparameters.Parameters.getCameraInitialDistance;
import static wormguides.util.subsceneparameters.Parameters.getCameraNearClip;
import static wormguides.util.subsceneparameters.Parameters.getDefaultOthersOpacity;
import static wormguides.util.subsceneparameters.Parameters.getInitialTranslateX;
import static wormguides.util.subsceneparameters.Parameters.getInitialTranslateY;
import static wormguides.util.subsceneparameters.Parameters.getInitialZoom;
import static wormguides.util.subsceneparameters.Parameters.getLabelSpriteYOffset;
import static wormguides.util.subsceneparameters.Parameters.getNoteBillboardTextWidth;
import static wormguides.util.subsceneparameters.Parameters.getNoteSpriteTextWidth;
import static wormguides.util.subsceneparameters.Parameters.getSelectabilityVisibilityCutoff;
import static wormguides.util.subsceneparameters.Parameters.getSizeScale;
import static wormguides.util.subsceneparameters.Parameters.getStoryOverlayPaneWidth;
import static wormguides.util.subsceneparameters.Parameters.getSubsceneBackgroundColorHex;
import static wormguides.util.subsceneparameters.Parameters.getUniformRadius;
import static wormguides.util.subsceneparameters.Parameters.getVisibilityCutoff;
import static wormguides.util.subsceneparameters.Parameters.getWaitTimeMilli;
/**
* The controller for the 3D subscene inside the rootEntitiesGroup layout. This class contains the subscene itself, and
* places it into the AnchorPane called modelAnchorPane inside the rootEntitiesGroup layout. It is also responsible
* for refreshing the scene on timeProperty, search, wormguides.stories, notes, and rules change. This class contains
* observable properties that are passed to other classes so that a subscene refresh can be trigger from that other
* class.
* <p>
* An "entity" in the subscene is either a cell, cell body, or multicellular structure. These are graphically
* represented by the Shape3Ds Sphere and MeshView available in JavaFX. {@link Sphere}s represent cells, and
* {@link MeshView}s represent cell bodies and multicellular structures. Notes and labels are rendered as
* {@link Text}s. This class queries the {@link LineageData} and {@link SceneElementsList} for a certain timeProperty
* and renders the entities, notes, story, and labels present in that timeProperty point.
* <p>
* For the coloring of entities, an observable list of {@link Rule}s is queried to see which ones apply to a
* particular entity, then queries the {@link ColorHash} for the {@link Material} to use for the entity.
*/
public class Window3DController {
private static final double CANNONICAL_ORIENTATION_X = 145.0;
private static final double CANNONICAL_ORIENTATION_Y = -166.0;
private static final double CANNONICAL_ORIENTATION_Z = 24.0;
private static final String CS = ", ";
private static final String ACTIVE_LABEL_COLOR_HEX = "#ffff66",
SPRITE_COLOR_HEX = "#ffffff",
TRANSIENT_LABEL_COLOR_HEX = "#f0f0f0";
private static final int X_COR_INDEX = 0,
Y_COR_INDEX = 1,
Z_COR_INDEX = 2;
/**
* Y offset of the callout line segment endpoint from the actual callout {@link Text}
**/
private static final int CALLOUT_LINE_Y_OFFSET = 10;
/**
* X offset of the callout line segment endpoint from the actual callout {@link Text}
**/
private static final int CALLOUT_LINE_X_OFFSET = 0;
// rotation stuff
private final Rotate rotateX;
private final Rotate rotateY;
private final Rotate rotateZ;
// transformation stuff
private final Group rootEntitiesGroup;
// switching timepoints stuff
private final BooleanProperty playingMovieProperty;
private final PlayService playService;
private final RenderService renderService;
/**
* Search results local to window 3d that only contains lineage names
*/
private final List<String> localSearchResults;
// color rules stuff
private final ColorHash colorHash;
private final Comparator<Color> colorComparator;
private final Comparator<Shape3D> opacityComparator;
// opacity value for "other" cells (with no rule attached)
private final DoubleProperty othersOpacityProperty;
private final List<String> otherCells;
private final Vector<JavaPicture> javaPictures;
private final SearchLayer searchLayer;
private final Stage parentStage;
private final LineageData lineageData;
private final SubScene subscene;
private final TextField searchField;
// housekeeping stuff
private final BooleanProperty rebuildSubsceneFlag;
private final DoubleProperty rotateXAngleProperty;
private final DoubleProperty rotateYAngleProperty;
private final DoubleProperty rotateZAngleProperty;
private final DoubleProperty translateXProperty;
private final DoubleProperty translateYProperty;
private final IntegerProperty timeProperty;
private final IntegerProperty totalNucleiProperty;
/**
* Start timeProperty of the lineage without movie timeProperty offset
*/
private final int startTime;
/**
* End timeProperty of the lineage without movie timeProperty offset
*/
private final int endTime;
private final DoubleProperty zoomProperty;
// Cell clicking/selection stuff
private final IntegerProperty selectedIndex;
private final StringProperty selectedNameProperty;
private final StringProperty selectedNameLabeledProperty;
private final Stage contextMenuStage;
private final ContextMenuController contextMenuController;
private final CasesLists casesLists;
private final BooleanProperty cellClickedProperty;
private final ObservableList<String> searchResultsList;
private final ObservableList<Rule> rulesList;
// Scene Elements stuff
private final boolean defaultEmbryoFlag;
private final SceneElementsList sceneElementsList;
// Story elements stuff
private final StoriesLayer storiesLayer;
/**
* Map of current note graphics to their note objects
*/
private final HashMap<Node, Note> currentGraphicNoteMap;
/**
* Map of current notes to their scene elements
*/
private final HashMap<Note, SceneElementMeshView> currentNoteMeshMap;
/**
* Map of note sprites attached to cell, or cell and timeProperty
*/
private final HashMap<Node, VBox> entitySpriteMap;
/**
* Map of front-facing billboards attached to cell, or cell and timeProperty
*/
private final HashMap<Node, Node> billboardFrontEntityMap;
/**
* Map of a cell entity to its label
*/
private final Map<Node, Text> entityLabelMap;
/**
* Map of upper left note callouts attached to a cell/structure
*/
private final HashMap<Node, List<Text>> entityCalloutULMap;
/**
* Map of upper right note callouts attached to a cell/structure
*/
private final HashMap<Node, List<Text>> entityCalloutURMap;
/**
* Map of lower left note callouts attached to a cell/structure
*/
private final HashMap<Node, List<Text>> entityCalloutLLMap;
/**
* Map of lower right note callouts attached to a cell/structure
*/
private final HashMap<Node, List<Text>> entityCalloutLRMap;
/* Map of all callout Texts to their Lines */
private final HashMap<Text, Line> calloutLineMap;
// orientation indicator
private final Cylinder orientationIndicator;
private final ProductionInfo productionInfo;
private final Connectome connectome;
private final BooleanProperty bringUpInfoFlag;
private final SubsceneSizeListener subsceneSizeListener;
// rotation - AP
private double[] keyValuesRotate;
private double[] keyFramesRotate;
// subscene state parameters
private LinkedList<Sphere> spheres;
private LinkedList<SceneElementMeshView> meshes;
private LinkedList<String> cellNames;
private LinkedList<String> meshNames;
private boolean[] isCellSearchedFlags;
private boolean[] isMeshSearchedFlags;
private LinkedList<Double[]> positions;
private LinkedList<Double> diameters;
private List<SceneElement> sceneElementsAtCurrentTime;
private List<SceneElementMeshView> currentSceneElementMeshes;
private List<SceneElement> currentSceneElements;
private PerspectiveCamera camera;
private Xform xform;
private double mousePosX, mousePosY, mousePosZ;
private double mouseOldX, mouseOldY, mouseOldZ;
// Label stuff
private double mouseDeltaX, mouseDeltaY;
// average position offsets of nuclei from zero
private int offsetX, offsetY, offsetZ;
private double angleOfRotation;
// searched highlighting stuff
private boolean isInSearchMode;
// Uniform nuclei sizef
private boolean uniformSize;
// Cell body and cell nucleus highlighting in search mode
private boolean cellNucleusTicked;
private boolean cellBodyTicked;
/**
* All notes that are active, or visible, in a frame
*/
private List<Note> currentNotes;
/**
* Rectangular box that resides in the upper-right-hand corner of the subscene. The active story title and
* description are shown here.
*/
private VBox storyOverlayVBox;
/**
* Overlay of the subscene. Note sprites are inserted into this overlay.
*/
private Pane spritesPane;
/**
* Labels that exist in any of the timeProperty frames
*/
private List<String> allLabels;
/**
* Labels currently visible in the frame
*/
private List<String> currentLabels;
/**
* Label that shows up on hover
*/
private Text transientLabelText;
private Rotate indicatorRotation;// this is the timeProperty varying component of
private BooleanProperty captureVideo;
private Timer timer;
private Vector<File> movieFiles;
private int count;
private String movieName;
private String moviePath;
private File frameDir;
private Stage timelineStage;
// private Quaternion quaternion;
/**
* X-scale of the subscene coordinate axis read from ProductionInfo.csv
*/
private double xScale;
/**
* Y-scale of the subscene coordinate axis read from ProductionInfo.csv
*/
private double yScale;
/**
* Z-scale of the subscene coordinate axis read from ProductionInfo.csv
*/
private double zScale;
public Window3DController(
final Stage parentStage,
final Group rootEntitiesGroup,
final SubScene subscene,
final AnchorPane parentPane,
final LineageData lineageData,
final CasesLists casesLists,
final ProductionInfo productionInfo,
final Connectome connectome,
final SceneElementsList sceneElementsList,
final TreeItem<StructureTreeNode> structureTreeRoot,
final StoriesLayer storiesLayer,
final SearchLayer searchLayer,
final BooleanProperty bringUpInfoFlag,
final int offsetX,
final int offsetY,
final int offsetZ,
final boolean defaultEmbryoFlag,
final double xScale,
final double yScale,
final double zScale,
final AnchorPane modelAnchorPane,
final Button backwardButton,
final Button forwardButton,
final Button zoomOutButton,
final Button zoomInButton,
final Button clearAllLabelsButton,
final TextField searchField,
final Slider opacitySlider,
final CheckBox uniformSizeCheckBox,
final CheckBox cellNucleusCheckBox,
final CheckBox cellBodyCheckBox,
final RadioButton multiRadioBtn,
final int startTime,
final int endTime,
final IntegerProperty timeProperty,
final IntegerProperty totalNucleiProperty,
final DoubleProperty zoomProperty,
final DoubleProperty othersOpacityProperty,
final DoubleProperty rotateXAngleProperty,
final DoubleProperty rotateYAngleProperty,
final DoubleProperty rotateZAngleProperty,
final DoubleProperty translateXProperty,
final DoubleProperty translateYProperty,
final StringProperty selectedNameProperty,
final StringProperty selectedNameLabeledProperty,
final BooleanProperty cellClickedFlag,
final BooleanProperty playingMovieFlag,
final BooleanProperty geneResultsUpdatedFlag,
final BooleanProperty rebuildSubsceneFlag,
final ObservableList<Rule> rulesList,
final ColorHash colorHash,
final Stage contextMenuStage,
final ContextMenuController contextMenuController,
final Service<Void> searchResultsUpdateService,
final ObservableList<String> searchResultsList,
final Stage timelineStage
) {
this.parentStage = requireNonNull(parentStage);
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
this.startTime = startTime;
this.endTime = endTime;
this.rootEntitiesGroup = requireNonNull(rootEntitiesGroup);
this.lineageData = lineageData;
this.productionInfo = requireNonNull(productionInfo);
this.connectome = requireNonNull(connectome);
this.sceneElementsList = requireNonNull(sceneElementsList);
this.storiesLayer = requireNonNull(storiesLayer);
this.searchLayer = requireNonNull(searchLayer);
this.defaultEmbryoFlag = defaultEmbryoFlag;
this.timeProperty = requireNonNull(timeProperty);
this.timeProperty.addListener((observable, oldValue, newValue) -> {
final int newTime = newValue.intValue();
final int oldTime = oldValue.intValue();
if (startTime <= newTime && newTime <= endTime) {
hideContextPopups();
} else if (newTime < startTime) {
timeProperty.set(startTime);
} else if (newTime > endTime) {
timeProperty.set(endTime);
}
});
// set orientation indicator frames and rotation from production info
keyFramesRotate = productionInfo.getKeyFramesRotate();
keyValuesRotate = productionInfo.getKeyValuesRotate();
// double[] initialRotation = productionInfo.getInitialRotation();
spheres = new LinkedList<>();
meshes = new LinkedList<>();
cellNames = new LinkedList<>();
meshNames = new LinkedList<>();
positions = new LinkedList<>();
diameters = new LinkedList<>();
isCellSearchedFlags = new boolean[1];
isMeshSearchedFlags = new boolean[1];
selectedIndex = new SimpleIntegerProperty(-1);
captureVideo = new SimpleBooleanProperty();
this.selectedNameProperty = requireNonNull(selectedNameProperty);
this.selectedNameProperty.addListener((observable, oldValue, newValue) -> {
int selected = getIndexByCellName(newValue);
if (selected != -1) {
selectedIndex.set(selected);
}
});
this.timelineStage = timelineStage;
this.selectedNameLabeledProperty = requireNonNull(selectedNameLabeledProperty);
this.selectedNameLabeledProperty.addListener((observable, oldValue, newValue) -> {
if (!newValue.isEmpty()) {
String lineageName = newValue;
this.selectedNameProperty.set(lineageName);
if (!allLabels.contains(lineageName)) {
allLabels.add(lineageName);
}
final Shape3D entity = getEntityWithName(lineageName);
// go to labeled name
int startTime1;
int endTime1;
startTime1 = getFirstOccurenceOf(lineageName);
endTime1 = getLastOccurenceOf(lineageName);
// do not change scene if entity does not exist at any timeProperty
if (startTime1 <= 0 || endTime1 <= 0) {
return;
}
if (timeProperty.get() < startTime1 || timeProperty.get() > endTime1) {
timeProperty.set(startTime1);
} else {
insertLabelFor(lineageName, entity);
}
insertLabelFor(lineageName, entity);
highlightActiveCellLabel(entity);
}
});
this.rulesList = requireNonNull(rulesList);
this.cellClickedProperty = requireNonNull(cellClickedFlag);
this.totalNucleiProperty = requireNonNull(totalNucleiProperty);
this.subscene = requireNonNull(subscene);
buildCamera();
parentPane.getChildren().add(this.subscene);
this.subscene.setFill(web(getSubsceneBackgroundColorHex()));
isInSearchMode = false;
subsceneSizeListener = new SubsceneSizeListener();
parentPane.widthProperty().addListener(subsceneSizeListener);
parentPane.heightProperty().addListener(subsceneSizeListener);
mousePosX = 0.0;
mousePosY = 0.0;
mousePosZ = 0.0;
mouseOldX = 0.0;
mouseOldY = 0.0;
mouseOldZ = 0.0;
mouseDeltaX = 0.0;
mouseDeltaY = 0.0;
angleOfRotation = 0.0;
playService = new PlayService();
this.playingMovieProperty = requireNonNull(playingMovieFlag);
this.playingMovieProperty.addListener((observable, oldValue, newValue) -> {
hideContextPopups();
if (newValue) {
playService.restart();
} else {
playService.cancel();
}
});
renderService = new RenderService();
this.zoomProperty = requireNonNull(zoomProperty);
this.zoomProperty.set(getInitialZoom());
this.zoomProperty.addListener((observable, oldValue, newValue) -> {
xform.setScale(zoomProperty.get());
repositionNotes();
});
xform.setScale(zoomProperty.get());
localSearchResults = new ArrayList<>();
requireNonNull(geneResultsUpdatedFlag).addListener((observable, oldValue, newValue) -> {
if (newValue) {
updateLocalSearchResults();
geneResultsUpdatedFlag.set(false);
}
});
otherCells = new ArrayList<>();
rotateX = new Rotate(0, X_AXIS);
rotateY = new Rotate(0, Y_AXIS);
rotateZ = new Rotate(0, Z_AXIS);
// initialize
this.rotateXAngleProperty = requireNonNull(rotateXAngleProperty);
this.rotateXAngleProperty.set(rotateX.getAngle());
this.rotateYAngleProperty = requireNonNull(rotateYAngleProperty);
this.rotateYAngleProperty.set(rotateY.getAngle());
this.rotateZAngleProperty = requireNonNull(rotateZAngleProperty);
this.rotateZAngleProperty.set(rotateZ.getAngle());
// add listener for control from rotationcontroller
this.rotateXAngleProperty.addListener(getRotateXAngleListener());
this.rotateYAngleProperty.addListener(getRotateYAngleListener());
this.rotateZAngleProperty.addListener(getRotateZAngleListener());
this.translateXProperty = requireNonNull(translateXProperty);
this.translateXProperty.addListener(getTranslateXListener());
this.translateXProperty.set(getInitialTranslateX());
this.translateYProperty = requireNonNull(translateYProperty);
this.translateYProperty.addListener(getTranslateYListener());
this.translateYProperty.set(getInitialTranslateY());
this.colorHash = requireNonNull(colorHash);
colorComparator = new ColorComparator();
opacityComparator = new OpacityComparator();
if (defaultEmbryoFlag) {
currentSceneElementMeshes = new ArrayList<>();
currentSceneElements = new ArrayList<>();
}
currentNotes = new ArrayList<>();
currentGraphicNoteMap = new HashMap<>();
currentNoteMeshMap = new HashMap<>();
entitySpriteMap = new HashMap<>();
billboardFrontEntityMap = new HashMap<>();
entityCalloutULMap = new HashMap<>();
entityCalloutURMap = new HashMap<>();
entityCalloutLLMap = new HashMap<>();
entityCalloutLRMap = new HashMap<>();
calloutLineMap = new HashMap<>();
allLabels = new ArrayList<>();
currentLabels = new ArrayList<>();
entityLabelMap = new HashMap<>();
final EventHandler<MouseEvent> mouseHandler = this::handleMouseEvent;
subscene.setOnMouseClicked(mouseHandler);
subscene.setOnMouseDragged(mouseHandler);
subscene.setOnMouseEntered(mouseHandler);
subscene.setOnMousePressed(mouseHandler);
subscene.setOnMouseReleased(mouseHandler);
final EventHandler<ScrollEvent> mouseScrollHandler = this::handleScrollEvent;
subscene.setOnScroll(mouseScrollHandler);
setNotesPane(parentPane);
this.casesLists = requireNonNull(casesLists);
movieFiles = new Vector<>();
javaPictures = new Vector<>();
count = -1;
// set up the orientation indicator in bottom right corner
double radius = 5.0;
double height = 15.0;
final PhongMaterial material = new PhongMaterial();
material.setDiffuseColor(RED);
orientationIndicator = new Cylinder(radius, height);
orientationIndicator.getTransforms().addAll(rotateX, rotateY, rotateZ);
orientationIndicator.setMaterial(material);
xform.getChildren().add(createOrientationIndicator());
this.bringUpInfoFlag = requireNonNull(bringUpInfoFlag);
this.rebuildSubsceneFlag = requireNonNull(rebuildSubsceneFlag);
// reset rebuild subscene flag to false because it may have been set to true by another layer's initialization
this.rebuildSubsceneFlag.set(false);
this.rebuildSubsceneFlag.addListener((observable, oldValue, newValue) -> {
if (newValue) {
buildScene();
final TimelineChart chart = TimelineChart.intialize(storiesLayer, productionInfo );
chart.rebuildTimeline(chart, timelineStage);
rebuildSubsceneFlag.set(false);
}
});
// set up the scaling value to convert from microns to pixel values, we set x,y = 1 and z = ratio of z to
// original y note that xScale and yScale are not the same
if (xScale != yScale) {
System.err.println(
"xScale does not equal yScale - using ratio of Z to X for zScale value in pixels\n"
+ "X, Y should be the same value");
}
this.xScale = 1;
this.yScale = 1;
this.zScale = zScale / xScale;
this.searchField = requireNonNull(searchField);
this.searchField.textProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.isEmpty()) {
isInSearchMode = false;
buildScene();
} else {
isInSearchMode = true;
}
});
requireNonNull(modelAnchorPane).setOnMouseClicked(getNoteClickHandler());
requireNonNull(backwardButton).setOnAction(getBackwardButtonListener());
requireNonNull(forwardButton).setOnAction(getForwardButtonListener());
requireNonNull(zoomOutButton).setOnAction(getZoomOutButtonListener());
requireNonNull(zoomInButton).setOnAction(getZoomInButtonListener());
this.othersOpacityProperty = requireNonNull(othersOpacityProperty);
requireNonNull(opacitySlider).valueProperty().addListener((observable, oldValue, newValue) -> {
final double newRounded = round(newValue.doubleValue()) / 100.0;
final double oldRounded = round(oldValue.doubleValue()) / 100.0;
if (newRounded != oldRounded) {
othersOpacityProperty.set(newRounded);
buildScene();
}
});
this.othersOpacityProperty.addListener((observable, oldValue, newValue) -> {
final double newVal = newValue.doubleValue();
final double oldVal = oldValue.doubleValue();
if (newVal != oldVal && newVal >= 0 && newVal <= 1.0) {
opacitySlider.setValue(newVal * 100);
}
});
this.othersOpacityProperty.setValue(getDefaultOthersOpacity());
uniformSizeCheckBox.setSelected(true);
uniformSize = true;
requireNonNull(uniformSizeCheckBox).selectedProperty().addListener((observable, oldValue, newValue) -> {
uniformSize = newValue;
buildScene();
});
requireNonNull(clearAllLabelsButton).setOnAction(getClearAllLabelsButtonListener());
requireNonNull(cellNucleusCheckBox).selectedProperty().addListener(getCellNucleusTickListener());
requireNonNull(cellBodyCheckBox).selectedProperty().addListener(getCellBodyTickListener());
requireNonNull(multiRadioBtn).selectedProperty().addListener(getMulticellModeListener());
this.contextMenuStage = requireNonNull(contextMenuStage);
this.contextMenuController = requireNonNull(contextMenuController);
requireNonNull(searchResultsUpdateService).setOnSucceeded(event -> updateLocalSearchResults());
this.searchResultsList = requireNonNull(searchResultsList);
this.captureVideo = new SimpleBooleanProperty();
}
/**
* Creates the orientation indicator and transforms
* <p>
* (for new model as of 1/5/2016)
*
* @return the group containing the orientation indicator texts
*/
private Group createOrientationIndicator() {
indicatorRotation = new Rotate();
// top level group
// had rotation to make it match main rotation
final Group orientationIndicator = new Group();
// has rotation to make it match biological orientation
final Group middleTransformGroup = new Group();
// set up the orientation indicator in bottom right corner
Text t = makeOrientationIndicatorText("A P");
t.setTranslateX(-10);
middleTransformGroup.getChildren().add(t);
t = makeOrientationIndicatorText("R L");
t.setTranslateX(-10);
t.setRotate(90);
middleTransformGroup.getChildren().add(t);
t = makeOrientationIndicatorText("V D");
t.setTranslateX(5);
t.setTranslateZ(15);
t.getTransforms().add(new Rotate(90, new Point3D(0, 1, 0)));
middleTransformGroup.getChildren().add(t);
// xy relocates z shrinks apparent by moving away from camera? improves resolution?
middleTransformGroup.getTransforms().add(new Scale(3, 3, 3));
// set the location of the indicator in the bottom right corner of the screen
orientationIndicator.getTransforms().add(new Translate(270, 200, 800));
// add rotation variables
orientationIndicator.getTransforms().addAll(rotateX, rotateY, rotateZ);
// add the directional symbols to the group
orientationIndicator.getChildren().add(middleTransformGroup);
// add rotation
middleTransformGroup.getTransforms().add(indicatorRotation);
return orientationIndicator;
}
private double computeInterpolatedValue(int timevalue, double[] keyFrames, double[] keyValues) {
if (timevalue <= keyFrames[0]) {
return keyValues[0];
}
if (timevalue >= keyFrames[keyFrames.length - 1]) {
return keyValues[keyValues.length - 1];
}
int i;
for (i = 0; i < keyFrames.length; i++) {
if (keyFrames[i] == timevalue) {
return (keyValues[i]);
}
if (keyFrames[i] > timevalue) {
break;
}
}
// interpolate btw values at i and i-1
double alpha = ((timevalue - keyFrames[i - 1]) / (keyFrames[i] - keyFrames[i - 1]));
double value = keyValues[i] * alpha + keyValues[i - 1] * (1 - alpha);
return value;
}
/**
* Inserts a transient label into the sprites pane for the specified entity if the entity is not an 'other' entity
* that has an opacity less than the cutoff (specified as a parameter in
* /wormguides/util/subsceneparameters/parameters.txt)
*
* @param name
* the name that appears on the transient label
* @param entity
* The entity that the label should appear on
*/
private void insertTransientLabel(String name, final Shape3D entity) {
final double opacity = othersOpacityProperty.get();
if (entity != null) {
// do not create transient label for "other" entities when their visibility is under the selectability
// cutoff
if ((entity.getMaterial() == colorHash.getOthersMaterial(opacity))
&& (othersOpacityProperty.get() < getSelectabilityVisibilityCutoff())) {
return;
}
if (!currentLabels.contains(name)) {
final Bounds b = entity.getBoundsInParent();
if (b != null) {
final String funcName = getFunctionalNameByLineageName(name);
if (funcName != null) {
name = funcName;
}
transientLabelText = makeNoteSpriteText(name);
transientLabelText.setWrappingWidth(-1);
transientLabelText.setFill(web(TRANSIENT_LABEL_COLOR_HEX));
transientLabelText.setOnMouseEntered(Event::consume);
transientLabelText.setOnMouseClicked(Event::consume);
final Point2D p = project(
camera,
new Point3D(
(b.getMinX() + b.getMaxX()) / 2,
(b.getMinY() + b.getMaxY()) / 2,
(b.getMaxZ() + b.getMinZ()) / 2));
double x = p.getX();
double y = p.getY();
y -= getLabelSpriteYOffset();
transientLabelText.getTransforms().add(new Translate(x, y));
// disable text to take away label flickering when mouse is on top top of it
transientLabelText.setDisable(true);
spritesPane.getChildren().add(transientLabelText);
}
}
}
}
/**
* Removes transient label from sprites pane.
*/
private void removeTransientLabel() {
spritesPane.getChildren().remove(transientLabelText);
}
/**
* Triggers zoom in and out on mouse wheel scroll
* DeltaY indicates the direction of scroll:
* -Y: zoom out
* +Y: zoom in
*
* @param se
* the scroll event
*/
public void handleScrollEvent(final ScrollEvent se) {
final EventType<ScrollEvent> type = se.getEventType();
if (type == SCROLL) {
double z = zoomProperty.get();
if (se.getDeltaY() < 0) {
// zoom out
if (z < 24.75) {
zoomProperty.set(z + 0.25);
}
} else if (se.getDeltaY() > 0) {
// zoom in
if (z > 0.25) {
z -= 0.25;
} else if (z < 0) {
z = 0;
}
zoomProperty.set(z);
}
}
}
@SuppressWarnings("unchecked")
public void handleMouseEvent(final MouseEvent me) {
final EventType<MouseEvent> type = (EventType<MouseEvent>) me.getEventType();
if (type == MOUSE_ENTERED_TARGET
|| type == MOUSE_ENTERED
|| type == MOUSE_RELEASED
|| type == MOUSE_MOVED) {
handleMouseReleasedOrEntered();
} else if (type == MOUSE_CLICKED && me.isStillSincePress()) {
handleMouseClicked(me);
} else if (type == MOUSE_DRAGGED) {
handleMouseDragged(me);
} else if (type == MOUSE_PRESSED) {
handleMousePressed(me);
}
}
private void handleMouseDragged(final MouseEvent event) {
hideContextPopups();
spritesPane.setCursor(CLOSED_HAND);
mouseOldX = mousePosX;
mouseOldY = mousePosY;
mouseOldZ = mousePosZ;
mousePosX = event.getSceneX();
mousePosY = event.getSceneY();
mouseDeltaX = (mousePosX - mouseOldX);
mouseDeltaY = (mousePosY - mouseOldY);
mouseDeltaX /= 2;
mouseDeltaY /= 2;
angleOfRotation = rotationAngleFromMouseMovement();
mousePosZ = computeZCoord(mousePosX, mousePosY, angleOfRotation);
if (event.isSecondaryButtonDown() || event.isMetaDown() || event.isControlDown()) {
final double translateX = xform.getTranslateX() - mouseDeltaX;
final double translateY = xform.getTranslateY() - mouseDeltaY;
xform.setTranslateX(translateX);
xform.setTranslateY(translateY);
translateXProperty.set(translateX);
translateYProperty.set(translateY);
repositionNotes();
} else {
if (event.isPrimaryButtonDown()) {
double modifier = 10.0;
double modifierFactor = 0.1;
rotateXAngleProperty.set((
(rotateXAngleProperty.get() + mouseDeltaY * modifierFactor * modifier * 2.0)
% 360 + 540) % 360 - 180);
rotateYAngleProperty.set((
(rotateYAngleProperty.get() + mouseDeltaX * modifierFactor * modifier * 2.0)
% 360 + 540) % 360 - 180);
repositionNotes();
}
}
}