Mercurial > hg > ccmieditor
comparison native/PhantomOmni/CollectionsManager.h @ 3:9e67171477bc
PHANTOM Omni Heptic device release
author | Fiore Martin <fiore@eecs.qmul.ac.uk> |
---|---|
date | Wed, 25 Apr 2012 17:09:09 +0100 |
parents | |
children | d66dd5880081 |
comparison
equal
deleted
inserted
replaced
2:4b2f975e35fa | 3:9e67171477bc |
---|---|
1 #pragma once | |
2 | |
3 #include <jni.h> | |
4 #include "stdafx.h" | |
5 #include "utils.h" | |
6 | |
7 | |
8 /* this class uses the java haptic object lists to provide nodes * | |
9 * and edges to draw to the graphic and haptic managers */ | |
10 class CollectionsManager | |
11 { | |
12 public: | |
13 struct NodeData { | |
14 jdouble x; | |
15 jdouble y; | |
16 jint hapticId; | |
17 jint diagramId; | |
18 | |
19 NodeData(){} | |
20 private : | |
21 NodeData(const NodeData& n){/* avoid mistakenly copy construction calls */} | |
22 }; | |
23 | |
24 struct EdgeData{ | |
25 jdouble *x; | |
26 jdouble *y; | |
27 bool **adjMatrix; | |
28 jint hapticId; | |
29 jint diagramId; | |
30 jint stipplePattern; | |
31 jsize nodeStart; | |
32 jdouble attractPoint[2]; | |
33 void setSize(unsigned int s){ | |
34 size = s; | |
35 if(s > previousSize){ | |
36 /* delete the old memory */ | |
37 delete [] x; | |
38 delete [] y; | |
39 for(unsigned int i=0; i<previousSize; i++) | |
40 delete[] adjMatrix[i]; | |
41 delete [] adjMatrix; | |
42 /* allocates a bigger one */ | |
43 try{ | |
44 x = new jdouble[size]; | |
45 y = new jdouble[size]; | |
46 adjMatrix = new bool* [size]; | |
47 for(unsigned int i=0; i<size; i++){ | |
48 adjMatrix[i] = new bool[size]; | |
49 for(unsigned int j=0; j<size; j++) | |
50 adjMatrix[i][j] = false; | |
51 } | |
52 }catch(std::bad_alloc){ | |
53 stopExecution("Could not allocate memory for the program.\nAborting..."); | |
54 } | |
55 previousSize = size; | |
56 } | |
57 } | |
58 | |
59 unsigned int getSize() const { | |
60 return size; | |
61 } | |
62 | |
63 EdgeData(unsigned int s) : size(s), previousSize(s){ | |
64 x = new jdouble[size]; | |
65 y = new jdouble[size]; | |
66 adjMatrix = new bool* [size]; | |
67 for(unsigned int i=0; i<size; i++){ | |
68 adjMatrix[i] = new bool[size]; | |
69 for(unsigned int j=0; j<size; j++) | |
70 adjMatrix[i][j] = false; | |
71 } | |
72 } | |
73 ~EdgeData(){ | |
74 delete [] x; | |
75 delete [] y; | |
76 for(unsigned int i=0; i<size; i++) | |
77 delete[] adjMatrix[i]; | |
78 delete [] adjMatrix; | |
79 } | |
80 private : | |
81 unsigned int size; | |
82 unsigned int previousSize; | |
83 EdgeData(const EdgeData& e){ /* avoid mistakenly copy construction */} | |
84 | |
85 }; | |
86 private: | |
87 JNIEnv *env; | |
88 jobject *haptics; | |
89 | |
90 jclass hapticClass; | |
91 jclass hapticNodeClass; | |
92 jclass hapticEdgeClass; | |
93 jclass listClass; | |
94 jclass bitsetClass; | |
95 jobject nodeList; | |
96 jobject edgeList; | |
97 jmethodID getMethodId; | |
98 jmethodID sizeMethodId; | |
99 jmethodID getBitMethodId; | |
100 jmethodID getNodeFromIDMethodId; | |
101 jmethodID getEdgeFromIDMethodId; | |
102 jfieldID xFieldId; | |
103 jfieldID yFieldId; | |
104 jfieldID nodeHapticIdFieldId; | |
105 jfieldID edgeHapticIdFieldId; | |
106 jfieldID nodeDiagramIdFieldId; | |
107 jfieldID edgeDiagramIdFieldId; | |
108 jfieldID nodeListfieldId; | |
109 jfieldID stipplePatternfieldId; | |
110 jfieldID edgeListfieldId; | |
111 jfieldID edgeSizefieldId; | |
112 jfieldID edgeXsFieldId; | |
113 jfieldID edgeYsFieldId; | |
114 jfieldID edgeAdjMatrixFieldId; | |
115 jfieldID attractPointXFieldId; | |
116 jfieldID attractPointYFieldId; | |
117 jfieldID edgeNodeStartFieldId; | |
118 | |
119 int screenHeight; | |
120 NodeData nd; | |
121 EdgeData ed; | |
122 | |
123 void fillupNodeData(struct NodeData & nd, jobject & currentNode); | |
124 void fillupEdgeData(struct EdgeData & ed, jobject & currentEdge); | |
125 public: | |
126 CollectionsManager(JNIEnv *environment, jobject *obj) : env(environment), haptics(obj), ed(2){} | |
127 virtual ~CollectionsManager(void){} | |
128 const jint getNodesNum(); | |
129 const jint getEdgesNum(); | |
130 struct NodeData & getNodeData(const int i); | |
131 struct EdgeData & getEdgeData(const int i); | |
132 struct NodeData & getNodeDataFromID(const jint id) throw(int); | |
133 struct EdgeData & getEdgeDataFromID(const jint id) throw(int); | |
134 bool isEdge(const jint id) const throw(int); | |
135 bool isNode(const jint id) const throw(int); | |
136 void init(void); | |
137 int getScreenHeight() const { return screenHeight;} | |
138 void setScreenHeight(const int sh) { screenHeight = sh; } | |
139 | |
140 }; |