3 using System.Collections.Generic;
23 public Vector3 x, y, z, origin;
25 public PlaneVectors(Vector3 x, Vector3 y, Vector3 z, Vector3 o)
38 private Plane[] pointPlanes;
39 private Plane[] labelPlanes;
46 private float[] initialPlaneRadius =
new float[4];
48 private Bounds meshBox;
49 private BoundingSphere bSphere;
51 private GameObject meshRotationNode;
52 private GameObject meshNode;
53 private GameObject meshPositionNode;
54 private GameObject meshViewerBase;
56 private List<GameObject> annotationList;
59 private Texture2D silhouetteImage;
61 private Camera silhouetteCam;
63 public bool autoHideAnnotations =
true;
65 private List<Label>[] labelLists =
new List<Label>[4];
66 private List<Point>[] pointsOnPlane =
new List<Point>[4];
68 private Quaternion meshRotation = Quaternion.identity;
70 private float rotationChange;
72 private float meshScale = 0;
73 private float scaleChange;
75 private int[] energyOfPlanes =
new int[4];
77 private bool switchToZoomPlane =
false;
80 private int counter = 0;
82 private float[] rads =
new float[360];
84 private bool inCalculationOfZoomPlane =
false;
85 private bool inCalculationOfPlanes =
false;
94 private int whichMode = 0;
96 private bool startRepositioning;
100 initialPlaneRadius =
new float[4];
102 pointPlanes =
new Plane[4];
103 labelPlanes =
new Plane[4];
108 meshViewerBase = GameObject.Find(
"MeshViewerBase");
109 meshRotationNode = GameObject.Find(
"MeshViewerBase/MeshViewerScale/MeshRotationNode");
110 meshNode = GameObject.Find(
"MeshViewerBase/MeshViewerScale");
111 meshPositionNode = GameObject.Find(
"MeshViewerBase/MeshViewerScale/MeshRotationNode/MeshPositionNode");
121 silhouetteCam = (Camera)Instantiate(
silhouetteCamPrefab, Camera.main.transform.position, Camera.main.transform.rotation);
122 silhouetteCam.transform.parent = this.transform;
124 annotationList = AnnotationControl.instance.getAnnotationList();
135 rotationChange = Quaternion.Angle(meshRotation, meshRotationNode.transform.rotation);
136 scaleChange = Math.Abs(meshNode.transform.localScale.x - meshScale);
138 if(annotationList != null)
140 if(annotationList.Count != 0)
142 if (annotationList[annotationList.Count - 1].GetComponent<
Annotation>().getLabel() != null)
151 public void forceRecalculate() {
154 startRepositioning =
true;
155 inCalculationOfPlanes =
false;
156 inCalculationOfZoomPlane =
false;
157 if(meshNode != null) {
168 annotationList = annoList;
171 startRepositioning =
true;
172 inCalculationOfPlanes =
false;
173 inCalculationOfZoomPlane =
false;
174 if(meshNode != null) {
180 public void resetAnnotationList() {
181 annotationList =
new List<GameObject> ();
192 private void updateAnnotation()
199 if (meshNode.transform.localScale.x < 1.2f)
201 bool[] whichPlane =
new bool[] {
false,
middlePlane,
true,
false };
203 if (switchToZoomPlane)
206 switchToZoomPlane =
false;
209 if (rotationChange >= 35 || scaleChange >= 0.25f || startRepositioning)
213 meshRotation = meshRotationNode.transform.rotation;
214 meshScale = meshNode.transform.localScale.x;
216 inCalculationOfPlanes =
true;
217 inCalculationOfZoomPlane =
false;
219 calculateEnergy(whichPlane);
221 startRepositioning =
false;
225 else if (whichMode == 1)
227 for (
int i = 0; i < labelLists.Length; i++)
229 labelLists[i] =
new List<Label>();
230 pointsOnPlane[i] =
new List<Point>();
232 createLabelCircle(switchToZoomPlane);
234 sortListsByAngle(whichPlane);
240 else if (whichMode == 0)
244 silhouetteCam.transform.position = Camera.main.transform.position;
245 silhouetteCam.transform.LookAt(meshBox.center);
256 else if (inCalculationOfPlanes)
258 calculateForces(switchToZoomPlane, whichPlane);
260 if(energyOfPlanes[2] == 0 || counter >
iterations)
262 inCalculationOfPlanes =
false;
271 bool[] whichPlane =
new bool[] {
false,
false,
false,
true };
273 if (!switchToZoomPlane)
276 switchToZoomPlane =
true;
278 if (rotationChange >= 15 || scaleChange >= 0.1f)
282 inCalculationOfPlanes =
false;
283 inCalculationOfZoomPlane =
true;
286 meshRotation = meshRotationNode.transform.rotation;
287 meshScale = meshNode.transform.localScale.x;
289 for (
int i = 0; i < labelLists.Length; i++)
291 labelLists[i] =
new List<Label>();
292 pointsOnPlane[i] =
new List<Point>();
295 createLabelCircle(switchToZoomPlane);
297 sortListsByAngle(whichPlane);
301 calculateEnergy(whichPlane);
305 else if (inCalculationOfZoomPlane)
308 switchToZoomPlane =
true;
310 calculateForces(switchToZoomPlane, whichPlane);
315 if(energyOfPlanes[3] == 0 || counter >
iterations)
317 inCalculationOfZoomPlane =
false;
331 private void sortListsByAngle(
bool[] whichPlane )
334 for(
int i = 0; i < labelLists.Length; i++)
338 labelLists[i].Sort((s1, s2) => s1.angle.CompareTo(s2.angle));
352 private void createLabelCircle(
bool zoomPlane)
356 for(
int i = 0; i < annotationList.Count; i++)
362 if (annotationList[i] != null)
365 planeNumber = updateWhichPlaneForPoint(annotationList[i], zoomPlane,
middlePlane);
368 p.planeNumber = planeNumber;
369 p = orthoProjectPointOnPlane(annotationList[i].transform.position, planeNumber, labelPlaneVectors[planeNumber], labelPlanes[planeNumber]);
370 p.annotationPoint = annotationList[i];
374 float radius = getInitialPlaneRadius(planeNumber);
376 Vector3 pointProjectedOnCircle = labelPlaneVectors[planeNumber].origin + radius * (p.position - labelPlaneVectors[planeNumber].origin).normalized;
378 float y = Vector3.Dot(pointProjectedOnCircle - labelPlaneVectors[planeNumber].origin, labelPlaneVectors[planeNumber].y);
379 float x = Vector3.Dot(pointProjectedOnCircle - labelPlaneVectors[planeNumber].origin, labelPlaneVectors[planeNumber].x);
381 Label l =
new Label(y, x, pointProjectedOnCircle, planeNumber, p.
angle, annotationList[i]);
384 l.calculateAngleToLeftAndRight(labelPlaneVectors[planeNumber].x, labelPlaneVectors[planeNumber].y, labelPlaneVectors[planeNumber].origin);
394 if (l.annotationLabel != null)
397 l.annotationLabel.SetActive(
true);
403 if (planeNumber != 3)
406 if( autoHideAnnotations )
407 l.annotationLabel.SetActive(
false);
413 l.annotationLabel.SetActive(
true);
414 l.annotationPoint.SetActive(
true);
415 labelLists[planeNumber].Add(l);
416 pointsOnPlane[planeNumber].Add(p);
423 if (planeNumber == 0 || planeNumber == 3)
426 if( autoHideAnnotations )
427 l.annotationLabel.SetActive(
false);
433 l.annotationLabel.SetActive(
true);
434 l.annotationPoint.SetActive(
true);
435 labelLists[planeNumber].Add(l);
436 pointsOnPlane[planeNumber].Add(p);
441 if (planeNumber != 2)
444 if( autoHideAnnotations )
445 l.annotationLabel.SetActive(
false);
451 l.annotationLabel.SetActive(
true);
452 l.annotationPoint.SetActive(
true);
453 labelLists[planeNumber].Add(l);
454 pointsOnPlane[planeNumber].Add(p);
464 calculateCenterOfZoomPlane(pointsOnPlane[3]);
473 private void defineNeighbours()
475 for (
int m = 0; m < labelLists.Length; m++)
477 for (
int j = 0; j < labelLists[m].Count; j++)
481 labelLists[m][j].leftLabel = labelLists[m][labelLists[m].Count - 1];
483 if (labelLists[m].Count >= 2)
485 labelLists[m][j].rightLabel = labelLists[m][j + 1];
489 labelLists[m][j].rightLabel = labelLists[m][j];
492 else if (j == labelLists[m].Count - 1)
494 labelLists[m][j].rightLabel = labelLists[m][0];
496 if (labelLists[m].Count >= 2)
498 labelLists[m][j].leftLabel = labelLists[m][j - 1];
502 labelLists[m][j].leftLabel = labelLists[m][j];
507 labelLists[m][j].rightLabel = labelLists[m][j + 1];
508 labelLists[m][j].leftLabel = labelLists[m][j - 1];
527 private void calculateForces(
bool zoomPlane,
bool[] whichPlane)
529 for (
int m = 0; m < labelLists.Length; m++)
533 for (
int j = 0; j < labelLists[m].Count; j++)
535 labelLists[m][j].dispAngle = 0;
537 if (labelLists[m][j].annotationLabel != null)
539 if (labelLists[m][j].annotationLabel.activeSelf)
541 for (
int u = 0; u < labelLists[m].Count; u++)
543 if (labelLists[m][u].annotationLabel != null)
545 if (labelLists[m][u].annotationLabel.activeSelf)
549 float angleOfForce = Vector3.Angle(labelLists[m][j].position, labelLists[m][u].position);
551 if (overlapLabelOnLabel(labelLists[m][j], labelLists[m][u]))
555 if (labelLists[m][j].angle > 180)
557 if (labelLists[m][u].angle < labelLists[m][j].angle - 180)
559 labelLists[m][j].dispAngle = labelLists[m][j].dispAngle - calculateRepForce(angleOfForce, labelLists[m][u].weight);
564 if (labelLists[m][u].angle > labelLists[m][j].angle)
567 labelLists[m][j].dispAngle = labelLists[m][j].dispAngle - calculateRepForce(angleOfForce, labelLists[m][u].weight);
573 labelLists[m][j].dispAngle = labelLists[m][j].dispAngle + calculateRepForce(angleOfForce, labelLists[m][u].weight);
580 if (labelLists[m][u].angle > labelLists[m][j].angle + 180)
583 labelLists[m][j].dispAngle = labelLists[m][j].dispAngle + calculateRepForce(angleOfForce, labelLists[m][u].weight);
587 if (labelLists[m][u].angle < labelLists[m][j].angle)
590 labelLists[m][j].dispAngle = labelLists[m][j].dispAngle + calculateRepForce(angleOfForce, labelLists[m][u].weight);
594 labelLists[m][j].dispAngle = labelLists[m][j].dispAngle - calculateRepForce(angleOfForce, labelLists[m][u].weight);
606 applyForcesOnLabels(zoomPlane, whichPlane);
619 private void applyForcesOnLabels(
bool zoomPlane,
bool[] whichPlane)
621 for (
int m = 0; m < labelLists.Length; m++)
625 calculateEnergy(whichPlane);
626 float maxDispAngle = energyOfPlanes[m];
628 for (
int j = 0; j < labelLists[m].Count; j++)
630 float angleToRight = 0;
631 float angleToLeft = 0;
633 if(labelLists[m][j].rightLabel.angle > labelLists[m][j].angle)
635 angleToRight = labelLists[m][j].rightLabel.angle - labelLists[m][j].angle;
639 angleToRight = (360 - labelLists[m][j].angle) + labelLists[m][j].rightLabel.angle;
642 if(labelLists[m][j].angle > labelLists[m][j].leftLabel.angle)
644 angleToLeft = labelLists[m][j].angle - labelLists[m][j].leftLabel.angle;
648 angleToLeft = (360 - labelLists[m][j].leftLabel.angle) + labelLists[m][j].angle;
651 labelLists[m][j].angleToLeftLabel = angleToLeft;
652 labelLists[m][j].angleToRightLabel = angleToRight;
654 if (labelLists[m][j].dispAngle > 0)
657 if (labelLists[m][j].angleToLeftLabel < labelLists[m][j].dispAngle)
660 labelLists[m][j].dispAngle = labelLists[m][j].angleToLeftLabel;
662 if (labelLists[m][j].dispAngle > maxDispAngle)
664 labelLists[m][j].dispAngle = maxDispAngle;
669 if (labelLists[m][j].dispAngle > maxDispAngle)
671 labelLists[m][j].dispAngle = maxDispAngle;
678 if (-labelLists[m][j].angleToRightLabel > labelLists[m][j].dispAngle)
680 labelLists[m][j].dispAngle = -(labelLists[m][j].angleToRightLabel);
682 if (labelLists[m][j].dispAngle < (-maxDispAngle))
684 labelLists[m][j].dispAngle = -maxDispAngle;
689 if (labelLists[m][j].dispAngle < (-maxDispAngle))
691 labelLists[m][j].dispAngle = -maxDispAngle;
696 labelLists[m][j].dispAngle = labelLists[m][j].dispAngle * Mathf.Deg2Rad;
698 float xNew = labelLists[m][j].x * Mathf.Cos(labelLists[m][j].dispAngle) - labelLists[m][j].y * Mathf.Sin(labelLists[m][j].dispAngle);
699 float yNew = labelLists[m][j].x * Mathf.Sin(labelLists[m][j].dispAngle) + labelLists[m][j].y * Mathf.Cos(labelLists[m][j].dispAngle);
701 labelLists[m][j].y = yNew;
702 labelLists[m][j].x = xNew;
704 labelLists[m][j].position = labelPlaneVectors[m].origin + yNew * labelPlaneVectors[m].y + xNew * labelPlaneVectors[m].x;
706 float angle = Vector3.Angle(labelLists[m][j].position - labelPlaneVectors[m].origin, labelPlaneVectors[m].origin + 2 * labelPlaneVectors[m].y);
709 if (labelLists[m][j].x >= 0)
718 labelLists[m][j].angle = angle;
719 labelLists[m][j].dispAngle = 0;
721 float newRadius = getInitialPlaneRadius(m);
723 labelLists[m][j].calculateCornersOnPlane(meshNode, meshPositionNode, meshViewerBase);
724 labelLists[m][j].calculateAngleToLeftAndRight(labelPlaneVectors[m].x, labelPlaneVectors[m].y, labelPlaneVectors[m].origin);
731 newRadius = findSmallestPossibleRadius(labelLists[m][j]);
734 if (newRadius > getInitialPlaneRadius(m))
736 newRadius = getInitialPlaneRadius(m);
746 newRadius = newRadius + offset;
748 labelLists[m][j].position = labelPlaneVectors[m].origin + newRadius * (labelLists[m][j].position - labelPlaneVectors[m].origin).normalized;
750 labelLists[m][j].y = Vector3.Dot(labelLists[m][j].position - labelPlaneVectors[m].origin, labelPlaneVectors[m].y);
751 labelLists[m][j].x = Vector3.Dot(labelLists[m][j].position - labelPlaneVectors[m].origin, labelPlaneVectors[m].x);
753 labelLists[m][j].calculateCornersOnPlane(meshNode, meshPositionNode, meshViewerBase);
754 labelLists[m][j].calculateAngleToLeftAndRight(labelPlaneVectors[m].x, labelPlaneVectors[m].y, labelPlaneVectors[m].origin);
758 labelLists[m][j].moveToNewPosition();
773 private float calculateRepForce(
float distance,
float k)
779 magnitude = -(k * k ) / distance;
783 magnitude = -(k * k) / 0.001f;
798 Vector3 center = meshNode.transform.position;
799 center = meshBox.center;
801 Vector3 planesNormal = (center - Camera.main.transform.position).normalized;
803 float distanceBetweenPointPlanes = bSphere.radius / 2;
805 Vector3 xAxis = planesNormal;
806 Vector3 yAxis = planesNormal;
807 Vector3 zAxis = planesNormal;
808 Vector3.OrthoNormalize(ref zAxis, ref yAxis, ref xAxis);
815 pointPlanes[0] =
new Plane();
816 pointPlanes[0].SetNormalAndPosition(planesNormal, center + (planesNormal * distanceBetweenPointPlanes));
818 labelPlanes[0] =
new Plane();
819 labelPlanes[0].SetNormalAndPosition(planesNormal, center + (planesNormal * distanceBetweenPointPlanes * 2));
821 pointPlaneVectors[0] =
new PlaneVectors(xAxis, -yAxis, zAxis, center + (planesNormal * distanceBetweenPointPlanes));
822 labelPlaneVectors[0] =
new PlaneVectors(xAxis, -yAxis, zAxis, center + (planesNormal * distanceBetweenPointPlanes * 2));
825 pointPlanes[1] =
new Plane();
826 pointPlanes[1].SetNormalAndPosition(planesNormal, center);
828 labelPlanes[1] =
new Plane();
829 labelPlanes[1].SetNormalAndPosition(planesNormal, center);
831 pointPlaneVectors[1] =
new PlaneVectors(xAxis, -yAxis, zAxis, center);
832 labelPlaneVectors[1] =
new PlaneVectors(xAxis, -yAxis, zAxis, center);
835 pointPlanes[2] =
new Plane();
836 pointPlanes[2].SetNormalAndPosition(planesNormal, center - (planesNormal * distanceBetweenPointPlanes));
838 labelPlanes[2] =
new Plane();
839 labelPlanes[2].SetNormalAndPosition(planesNormal, center - (planesNormal * distanceBetweenPointPlanes * 2));
841 pointPlaneVectors[2] =
new PlaneVectors(xAxis, -yAxis, zAxis, center - (planesNormal * distanceBetweenPointPlanes));
842 labelPlaneVectors[2] =
new PlaneVectors(xAxis, -yAxis, zAxis, center - (planesNormal * distanceBetweenPointPlanes * 2));
846 RaycastHit hit =
new RaycastHit();
848 int layerMask = 1 << 9;
850 float maxDistance = (Camera.main.transform.position - meshBox.center).magnitude;
854 Ray ray =
new Ray(Camera.main.transform.position, meshBox.center - Camera.main.transform.position);
855 Physics.Raycast(ray, out hit, maxDistance, layerMask);
858 Vector3 zoomPlaneLabelCenter = Camera.main.transform.position +
zoomPlaneDistance * planesNormal;
859 Vector3 zoomPlanePointCenter = hit.point;
861 Debug.DrawLine(Camera.main.transform.position, zoomPlanePointCenter);
864 pointPlanes[3] =
new Plane();
865 pointPlanes[3].SetNormalAndPosition(planesNormal, zoomPlanePointCenter);
867 labelPlanes[3] =
new Plane();
868 labelPlanes[3].SetNormalAndPosition(planesNormal, zoomPlaneLabelCenter);
870 pointPlaneVectors[3] =
new PlaneVectors(xAxis, -yAxis, zAxis, zoomPlanePointCenter);
871 labelPlaneVectors[3] =
new PlaneVectors(xAxis, -yAxis, zAxis, zoomPlaneLabelCenter);
882 private void calculateCenterOfZoomPlane(List<Point> listOfPointsInZoomPlane)
887 foreach (
Point p
in listOfPointsInZoomPlane)
892 if (listOfPointsInZoomPlane.Count != 0)
894 yCenter = yCenter / listOfPointsInZoomPlane.Count;
895 xCenter = xCenter / listOfPointsInZoomPlane.Count;
898 labelPlaneVectors[3].origin = labelPlaneVectors[3].origin + labelPlaneVectors[3].y * yCenter + labelPlaneVectors[3].x * xCenter;
899 pointPlaneVectors[3].origin = pointPlaneVectors[3].origin + labelPlaneVectors[3].y * yCenter + labelPlaneVectors[3].x * xCenter;
902 for (
int i = 0; i < pointsOnPlane[3].Count; i++)
904 Point p = orthoProjectPointOnPlane(pointsOnPlane[3][i].annotationPoint.transform.position, 3, labelPlaneVectors[3], labelPlanes[3]);
905 pointsOnPlane[3][i].position = p.position;
906 pointsOnPlane[3][i].angle = p.angle;
907 pointsOnPlane[3][i].x = p.x;
908 pointsOnPlane[3][i].y = p.y;
909 pointsOnPlane[3][i].z = p.z;
911 Vector3 pointProjectedOnCircle = labelPlaneVectors[3].origin + initialPlaneRadius[3] * (p.position - labelPlaneVectors[3].origin).normalized;
912 float y = Vector3.Dot(pointProjectedOnCircle - labelPlaneVectors[3].origin, labelPlaneVectors[3].y);
913 float x = Vector3.Dot(pointProjectedOnCircle - labelPlaneVectors[3].origin, labelPlaneVectors[3].x);
915 pointsOnPlane[3][i].label.position = pointProjectedOnCircle;
916 pointsOnPlane[3][i].label.x = x;
917 pointsOnPlane[3][i].label.y = y;
918 pointsOnPlane[3][i].label.angle = p.angle;
922 sortListsByAngle(
new bool[] {
false,
false,
false,
true });
934 private int updateWhichPlaneForPoint(GameObject annoPoint,
bool zoomPlane,
bool middlePlane)
937 Vector3 pointPosition = annoPoint.transform.position;
941 float d2 = pointPlanes[1].GetDistanceToPoint(pointPosition);
943 float d3 = pointPlanes[2].GetDistanceToPoint(pointPosition);
945 float d4 = pointPlanes[3].GetDistanceToPoint(pointPosition);
958 Point p = orthoProjectPointOnPlane(annoPoint.transform.position, 3, pointPlaneVectors[3], pointPlanes[3]);
977 if(Mathf.Abs(d3) <= Mathf.Abs(d2))
1004 private float getInitialPlaneRadius(
int planeNumber)
1006 initialPlaneRadius[0] = 0;
1007 initialPlaneRadius[1] = bSphere.radius * 1.05f;
1008 initialPlaneRadius[2] = bSphere.radius;
1011 return initialPlaneRadius[planeNumber];
1018 private void createBoundingBox()
1023 MeshRenderer mesh =
new MeshRenderer();
1025 meshBox =
new Bounds(meshNode.transform.position, Vector3.zero);
1026 bSphere =
new BoundingSphere();
1028 for (
int i = 0; i < meshPositionNode.transform.childCount; i++)
1030 Transform child = meshPositionNode.transform.GetChild(i);
1032 if (child.tag !=
"Annotation")
1035 for (
int j = 0; j < child.childCount; j++)
1038 Transform childChild = child.GetChild(j);
1040 mesh = childChild.GetComponent<MeshRenderer>();
1044 meshBox.Encapsulate(mesh.bounds);
1050 bSphere.position = meshBox.center;
1051 bSphere.radius = Mathf.Max(meshBox.extents.x, meshBox.extents.y, meshBox.center.z);
1060 private void drawPlane()
1062 Vector3 y = pointPlaneVectors[0].y;
1063 Vector3 z = pointPlaneVectors[0].z;
1066 Debug.DrawLine(pointPlaneVectors[0].origin + (2 * z + 2 * y), pointPlaneVectors[0].origin + (2 * z - 2 * y), Color.red, 5f);
1067 Debug.DrawLine(pointPlaneVectors[0].origin + (2 * z - 2 * y), pointPlaneVectors[0].origin + (- 2 * z - 2 * y), Color.red, 5f);
1068 Debug.DrawLine(pointPlaneVectors[0].origin + (- 2 * z - 2 * y), pointPlaneVectors[0].origin + (- 2 * z + 2 * y), Color.red, 5f);
1069 Debug.DrawLine(pointPlaneVectors[0].origin + (- 2 * z + 2 * y), pointPlaneVectors[0].origin + (2 * z + 2 * y), Color.red, 5f);
1083 private Point orthoProjectPointOnPlane(Vector3 pointPosition,
int planeNumber, PlaneVectors planeVector, Plane plane)
1088 Vector3 pointPos = pointPosition;
1089 Vector3 planeOrigin = planeVector.origin;
1090 Vector3 planeNormal = planeVector.z;
1094 float distance = plane.GetDistanceToPoint(pointPos);
1096 Vector3 projectedPoint = pointPos + planeNormal * distance;
1100 y = Vector3.Dot(projectedPoint - planeOrigin, planeVector.y);
1101 x = Vector3.Dot(projectedPoint - planeOrigin, planeVector.x);
1107 float angle = Vector3.Angle(projectedPoint - planeOrigin, planeOrigin + 2 * planeVector.y);
1115 angle = 360 - angle;
1121 p.planeNumber = planeNumber;
1122 p.position = projectedPoint;
1132 private void OnDrawGizmos()
1134 Gizmos.DrawWireCube(meshBox.center, meshBox.size);
1145 private bool overlapLabelOnLabel(
Label li,
Label lj)
1147 float[] overlap =
new float[2];
1153 GameObject labeli = li.annotationLabel;
1154 GameObject labelj = lj.annotationLabel;
1156 if (labeli != null && labelj != null)
1159 widthi = labeli.GetComponent<RectTransform>().rect.width * labeli.GetComponent<RectTransform>().localScale.x * labeli.transform.parent.localScale.x * meshNode.transform.localScale.x * meshPositionNode.transform.localScale.x * meshViewerBase.transform.localScale.x;
1160 heighti = labeli.GetComponent<RectTransform>().rect.height * labeli.GetComponent<RectTransform>().localScale.x * labeli.transform.parent.localScale.x * meshNode.transform.localScale.x * meshPositionNode.transform.localScale.x * meshViewerBase.transform.localScale.x;
1161 widthj = labelj.GetComponent<RectTransform>().rect.width * labelj.GetComponent<RectTransform>().localScale.x * labeli.transform.parent.localScale.x * meshNode.transform.localScale.x * meshPositionNode.transform.localScale.x * meshViewerBase.transform.localScale.x;
1162 heightj = labelj.GetComponent<RectTransform>().rect.height * labelj.GetComponent<RectTransform>().localScale.x * labeli.transform.parent.localScale.x * meshNode.transform.localScale.x * meshPositionNode.transform.localScale.x * meshViewerBase.transform.localScale.x;
1181 else if (Mathf.Abs(yi - yj) <= ((heighti / 2) + (heightj / 2)))
1195 else if (Mathf.Abs(xi - xj) <= ((widthi / 2) + (widthj / 2)))
1203 if (overlap[0] == 1 && overlap[1] == 1)
1220 private void calculateEnergy(
bool[] whichPlanes)
1222 for (
int p = 0; p < labelLists.Length; p++)
1226 energyOfPlanes[p] = 0;
1228 for (
int j = 0; j < labelLists[p].Count; j++)
1230 for (
int l = j; l < labelLists[p].Count; l++)
1234 if (overlapLabelOnLabel(labelLists[p][j], labelLists[p][l]))
1236 energyOfPlanes[p]++;
1254 private float calculateSilouhette(Vector3 position, Camera cam, Texture2D image,
int planeNumber)
1257 float maxRadius = getInitialPlaneRadius(planeNumber);
1261 Vector3 centerIn3DOnCamPlane = cam.WorldToScreenPoint(labelPlaneVectors[1].origin);
1262 Vector2 centerIn2D =
new Vector2(centerIn3DOnCamPlane.x, centerIn3DOnCamPlane.y);
1264 float distance = centerIn3DOnCamPlane.z;
1268 Vector3 pointPosIn3D = cam.WorldToScreenPoint(position);
1269 Vector2 pointPosIn2D =
new Vector2(pointPosIn3D.x, pointPosIn3D.y);
1273 Vector2 pEdge = bresenhamLine((
int)pointPosIn2D.x, (
int)pointPosIn2D.y, (
int)centerIn2D.x, (
int)centerIn2D.y, image);
1275 Vector3 pEdgeInWorld = cam.ScreenToWorldPoint(
new Vector3(pEdge.x, pEdge.y, distance));
1277 Vector3 centerIn3DInWorld = cam.ScreenToWorldPoint(centerIn3DOnCamPlane);
1278 centerIn3DInWorld = labelPlaneVectors[1].origin;
1280 radius = (pEdgeInWorld - centerIn3DInWorld).magnitude;
1286 else if(radius > maxRadius)
1292 Debug.DrawRay(centerIn3DInWorld, (pEdgeInWorld - centerIn3DInWorld).normalized * radius, Color.red, 0.20f);
1307 private Vector2 bresenhamLine(
int x,
int y,
int x2,
int y2, Texture2D image)
1311 int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
1312 if (w < 0) dx1 = -1;
else if (w > 0) dx1 = 1;
1313 if (h < 0) dy1 = -1;
else if (h > 0) dy1 = 1;
1314 if (w < 0) dx2 = -1;
else if (w > 0) dx2 = 1;
1315 int longest = Mathf.Abs(w);
1316 int shortest = Mathf.Abs(h);
1317 if (!(longest > shortest))
1319 longest = Mathf.Abs(h);
1320 shortest = Mathf.Abs(w);
1321 if (h < 0) dy2 = -1;
else if (h > 0) dy2 = 1;
1324 int numerator = longest >> 1;
1326 for (
int i = 0; i <= longest; i++)
1330 if (image.GetPixel(x, y) != Color.white)
1332 image.SetPixel(x, y, Color.blue);
1348 Vector2 pos =
new Vector2(x, y);
1365 numerator += shortest;
1366 if (!(numerator < longest))
1368 numerator -= longest;
1382 Vector2 center =
new Vector2(0, 0);
1392 private void takePicture()
1399 RenderTexture.active = silhouetteCam.targetTexture;
1400 silhouetteCam.Render();
1401 silhouetteImage =
new Texture2D(silhouetteCam.targetTexture.width, silhouetteCam.targetTexture.height);
1402 silhouetteImage.ReadPixels(
new Rect(0, 0, silhouetteCam.targetTexture.width, silhouetteCam.targetTexture.height), 0, 0);
1403 silhouetteImage.Apply();
1411 private void drawPicture()
1414 Byte[] b = silhouetteImage.EncodeToPNG();
1416 File.WriteAllBytes(
"C:/Users/Ben/Desktop/Image.png", b);
1423 private void createPie()
1427 p.y = bSphere.radius;
1428 p.position = labelPlaneVectors[1].origin + (initialPlaneRadius[1]) * labelPlaneVectors[1].y;
1435 for (
int i = 0; i < rads.Length; i++)
1438 rads[rads.Length - 1 - i] = (((Camera.main.transform.position - labelPlaneVectors[2].origin).magnitude) * calculateSilouhette(p.
position, silhouetteCam, silhouetteImage, 1)) / ((Camera.main.transform.position - meshBox.center).magnitude);
1440 rotangle = 1 * Mathf.Deg2Rad;
1442 xNew = p.x * Mathf.Cos(rotangle) - p.y * Mathf.Sin(rotangle);
1443 yNew = p.x * Mathf.Sin(rotangle) + p.y * Mathf.Cos(rotangle);
1448 p.position = labelPlaneVectors[1].origin + labelPlaneVectors[1].y * p.y + labelPlaneVectors[1].x * p.x;
1459 private float findSmallestPossibleRadius(
Label l)
1481 float[] rads1 =
new float[angleSize];
1484 if((startAngle + angleSize) < 360)
1486 for (
int i = 0; i < angleSize; i++)
1489 rads1[i] = rads[startAngle + i];
1495 for (
int i = 0; i < 360 - startAngle; i++)
1498 rads1[i] = rads[startAngle + i];
1501 for(
int i = 0; i < angleSize - (360 - startAngle); i++)
1505 rads1[(360 - startAngle) + i] = ko;
1511 return rads1[rads1.Length - 1];
float[] angleToLeftAndRightCorner
GameObject annotationPoint
float zoomPlaneDetectionRadius
void updateAnnotationList(List< GameObject > annoList)
Called by Annotation Control to update Annotation List when it changes
Camera silhouetteCamPrefab
float weightAngleSizeRatio