@ndmspc/ndmvr 0.1.1 → 0.20220401.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +359 -2
- package/dist/index.js +2202 -1704
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +2202 -1705
- package/dist/index.modern.js.map +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,16 +1,289 @@
|
|
|
1
1
|
# ndmvr
|
|
2
2
|
|
|
3
|
-
> NDimensional VR library
|
|
4
|
-
|
|
5
3
|
[](https://www.npmjs.com/package/@ndmspc/ndmvr)
|
|
6
4
|
[](https://standardjs.com)
|
|
7
5
|
|
|
6
|
+
> NDimensional VR library
|
|
7
|
+
|
|
8
|
+
**NDMVR** is a package of the components that are used in the visualization of the histograms of the type such as TH in virtual reality.
|
|
9
|
+
|
|
10
|
+
Library for displaying TH histograms in virtual reality.
|
|
11
|
+
|
|
12
|
+
> ### Library provides:
|
|
13
|
+
>
|
|
14
|
+
> - ndmVrHistogramScene
|
|
15
|
+
> - ndmVrStorage
|
|
16
|
+
> - jsrootHistogram
|
|
17
|
+
>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
8
21
|
## Install
|
|
9
22
|
|
|
10
23
|
```bash
|
|
11
24
|
npm install --save @ndmspc/ndmvr
|
|
12
25
|
```
|
|
13
26
|
|
|
27
|
+
After installation, you have 3 components which you can import and use.
|
|
28
|
+
|
|
29
|
+
<code>import { ndmVrStorage, NdmVrScene, JSrootHistogram } from '@ndmspc/ndmvr'</code>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
To display the controls and background, you need to provide a file that contains the necessary resources, such as images. The user can then add their own backgrounds to the scene to the file structure and then use them to integrate the component. It is also possible to customize the controls according to the nature of the client application by editing textures.
|
|
33
|
+
|
|
34
|
+
Otherwise, the user will have functional components that do not contain the appropriate textures.
|
|
35
|
+
|
|
36
|
+
File structure:
|
|
37
|
+
|
|
38
|
+
``` sh
|
|
39
|
+
ndmvr
|
|
40
|
+
├── backgrounds
|
|
41
|
+
│ └── background1.png
|
|
42
|
+
│ └── background2.jpg
|
|
43
|
+
│ └── ...
|
|
44
|
+
├── keybordControls
|
|
45
|
+
│ └── keyboard.png
|
|
46
|
+
│ └── keuboard1.png
|
|
47
|
+
│ └── keyboard2.png
|
|
48
|
+
│ └── keuboard3.png
|
|
49
|
+
├── oculusControls
|
|
50
|
+
│ └── oculus.png
|
|
51
|
+
│ └── oculus1.png
|
|
52
|
+
│ └── oculus2.png
|
|
53
|
+
│ └── oculus3.png
|
|
54
|
+
└── ...
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The file must be placed in the `public` directory in the client application to ensure access to resources in the project.
|
|
58
|
+
|
|
59
|
+
To load all the default textures and resources for control and interaction, you must obtain the default file by downloading project resources:
|
|
60
|
+
|
|
61
|
+
>
|
|
62
|
+
>- [zip](https://gitlab.com/ndmspc/ndmvr/-/archive/v0.1.0/ndmvr-v0.1.0.zip)
|
|
63
|
+
>- [tar.gz](https://gitlab.com/ndmspc/ndmvr/-/archive/v0.1.0/ndmvr-v0.1.0.tar.gz)
|
|
64
|
+
>- [tar.bz2](https://gitlab.com/ndmspc/ndmvr/-/archive/v0.1.0/ndmvr-v0.1.0.tar.bz2)
|
|
65
|
+
>- [tar](https://gitlab.com/ndmspc/ndmvr/-/archive/v0.1.0/ndmvr-v0.1.0.tar)
|
|
66
|
+
>
|
|
67
|
+
|
|
68
|
+
After obtaining the resources, it is necessary to move the `etc / ndmvr` directory to the` public` directory in the client application.
|
|
69
|
+
|
|
70
|
+
Subsequently, everything is ready to use the package in the client application.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### Prepare environment
|
|
74
|
+
|
|
75
|
+
For the use of this technology, it is necessary to have an appropriate environment for development, which depends on [Node >= 10.16](https://nodejs.org/en/) and the package manager such as [npm](https://www.npmjs.com/package/@ndmspc/ndmvr). The components have been developed using library [React](https://reactjs.org/docs/getting-started.html#try-react). From that reason, it is possible to integrate only in applications with the react.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Components
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### JsrootHistogram
|
|
84
|
+
|
|
85
|
+
The component displays JSROOT projections.
|
|
86
|
+
|
|
87
|
+
The example shows a projection from the root structure. In this case,`projIndex` is important and determines projection in the array.
|
|
88
|
+
```jsx
|
|
89
|
+
<JSrootHistogram histogram={histogram} projectionAxes={['X','Y']} projections={projections} projIndex={0}/>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The example shows a creating projection on axes X and Y. In this case, `projIndex` is useless.
|
|
93
|
+
|
|
94
|
+
```jsx
|
|
95
|
+
<JSrootHistogram histogram={histogram} projectionAxes={['X','Y']} projections={null} projIndex={0}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### attribute ***histogram***
|
|
99
|
+
|
|
100
|
+
This object defines main histogram TH.
|
|
101
|
+
We get this object from ROOT file.
|
|
102
|
+
More info about th histograms and objects are [here]()
|
|
103
|
+
|
|
104
|
+
| Property | Type | Description | Default | Optional |
|
|
105
|
+
| ------ | ------ | ------ | ------ | ------ |
|
|
106
|
+
| **histogram** | Object | Main object defines histogram for displaying | `null` | `False` |
|
|
107
|
+
|
|
108
|
+
#### attribute ***projections***
|
|
109
|
+
|
|
110
|
+
File structure contains organised directories and projections for each bin of the main histogram.
|
|
111
|
+
|
|
112
|
+
| Property | Type | Description | Default | Optional |
|
|
113
|
+
| ------ | ------ | ------ | ------ | ------ |
|
|
114
|
+
| **projections** | Object | File structure with projection | `null` | `True` |
|
|
115
|
+
|
|
116
|
+
Structure of the files can look like that:
|
|
117
|
+
|
|
118
|
+
``` sh
|
|
119
|
+
.
|
|
120
|
+
├── 1
|
|
121
|
+
│ └── 1
|
|
122
|
+
│ │ └── projectionArray
|
|
123
|
+
│ └── 2
|
|
124
|
+
│ └── 3
|
|
125
|
+
│ └── 4
|
|
126
|
+
│ └── ...
|
|
127
|
+
├── 2
|
|
128
|
+
│ └── 1
|
|
129
|
+
│ └── 2
|
|
130
|
+
│ └── ...
|
|
131
|
+
└── ...
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Displayed file structure describes the template where each bin has her own projection array addressed in directories with path, which determines the bin's coordinates.
|
|
135
|
+
As we can see, the bin with x coordinate 1 and y coordinate 1 has a projection stored in a directory with path `root/1/1/projArray[0]`.
|
|
136
|
+
|
|
137
|
+
#### attribute ***projectionAxes***
|
|
138
|
+
|
|
139
|
+
To create 2-dimensional projection we define attribute as an array with names of the axes.
|
|
140
|
+
|
|
141
|
+
This attribute is optional.
|
|
142
|
+
|
|
143
|
+
| Property | Type | Description | Default | Optional |
|
|
144
|
+
| ------ | ------ | ------ | ------ | ------ |
|
|
145
|
+
| **projectionAxes** | Array | Array of projection objects | `null` | `True` |
|
|
146
|
+
|
|
147
|
+
#### attribute ***projIndex***
|
|
148
|
+
|
|
149
|
+
Choose the right projection from the projection array of the root directory.
|
|
150
|
+
|
|
151
|
+
| Property | Type | Description | Default | Optional |
|
|
152
|
+
| ------ | ------ | ------ | ------ | ------ |
|
|
153
|
+
| **projIndex** | number | index of the projection in array | `0` | `True` |
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
### NdmVRHistogramScene
|
|
157
|
+
|
|
158
|
+
The component is primary maintained for displaying VR scene with TH histogram. It contains 2 properties such as data and info.
|
|
159
|
+
|
|
160
|
+
```jsx
|
|
161
|
+
<NdmVrScene data={data} info={info} />
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Properties are defined as an object with the necessary data.
|
|
165
|
+
|
|
166
|
+
- **data** - primary data such as histogram object, projections...
|
|
167
|
+
- **info** - secondary data for define schemes, background attributes...
|
|
168
|
+
|
|
169
|
+
#### attribute ***data***
|
|
170
|
+
|
|
171
|
+
| Property | Type | Description | Default | Optional |
|
|
172
|
+
| ------ | ------ | ------ | ------ | ------ |
|
|
173
|
+
| **histogram** | Object | Main object defines histogram for displaying | `null` | `False` |
|
|
174
|
+
| **projections** | Object | File structure with projection | `null` | `True` |
|
|
175
|
+
| **section** | Object | Data about offsets and histogram type | -- | `True` |
|
|
176
|
+
|
|
177
|
+
##### object ***histogram***
|
|
178
|
+
|
|
179
|
+
This object defines main histogram TH.
|
|
180
|
+
We get this object from ROOT file.
|
|
181
|
+
More info about th histograms and objects are [here]()
|
|
182
|
+
|
|
183
|
+
##### object ***projections***
|
|
184
|
+
|
|
185
|
+
File structure contains organised directories and projections for each bin of the main histogram.
|
|
186
|
+
Structure of the files can look like that:
|
|
187
|
+
|
|
188
|
+
``` sh
|
|
189
|
+
.
|
|
190
|
+
├── 1
|
|
191
|
+
│ └── 1
|
|
192
|
+
│ │ └── projectionArray
|
|
193
|
+
│ └── 2
|
|
194
|
+
│ └── 3
|
|
195
|
+
│ └── 4
|
|
196
|
+
│ └── ...
|
|
197
|
+
├── 2
|
|
198
|
+
│ └── 1
|
|
199
|
+
│ └── 2
|
|
200
|
+
│ └── ...
|
|
201
|
+
└── ...
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Displayed file structure describes the template where each bin has her own projection array addressed in directories with path, which determines the bin's coordinates.
|
|
205
|
+
As we can see, the bin with x coordinate 1 and y coordinate 1 has a projection stored in a directory with path `root/1/1/projArray[0]`.
|
|
206
|
+
|
|
207
|
+
##### object ***section***
|
|
208
|
+
|
|
209
|
+
The object defines data for displaying the right amount of data. The face of the object represents attributes for offset throughout axes, range and the typename of the histogram. The parameter is optional.
|
|
210
|
+
|
|
211
|
+
Range defines how many bins will be displayed on an axis. In overall in Th3 histogram will be displayed (range+1 * range+1 * range+1) bins.
|
|
212
|
+
|
|
213
|
+
The object should look like that:
|
|
214
|
+
|
|
215
|
+
``` js
|
|
216
|
+
{
|
|
217
|
+
name: 'TH3',
|
|
218
|
+
xOffset: 1,
|
|
219
|
+
yOffset: 1,
|
|
220
|
+
zOffset: 1,
|
|
221
|
+
range: 20
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### attribute ***info***
|
|
226
|
+
|
|
227
|
+
This parameter is used for defining general information about histograms and themes.
|
|
228
|
+
|
|
229
|
+
The object defines the scale and url of the image background, a user could use his or her own background image so that the user could save these images in the `public` directory of the client application.
|
|
230
|
+
|
|
231
|
+
Main properties of the object info:
|
|
232
|
+
|
|
233
|
+
| Property | Type | Description | Default | Optional |
|
|
234
|
+
| ------ | ------ | ------ | ------ | ------ |
|
|
235
|
+
| **name** | String | Unique name of the histogram | `null` | `True` |
|
|
236
|
+
| **theme** | String | String defines theme | `def` | `False` |
|
|
237
|
+
| **background** | Object | Object defines background properties | `null` | `True` |
|
|
238
|
+
|
|
239
|
+
Main properties of the object background:
|
|
240
|
+
|
|
241
|
+
| Property | Type | Description | Default | Optional |
|
|
242
|
+
| ------ | ------ | ------ | ------ | ------ |
|
|
243
|
+
| **url** | String | defines url of the background image | `./ndmvr/backgrounds/background1.jpg` | `False` |
|
|
244
|
+
| **radius** | number | background radius | `3000` | `False` |
|
|
245
|
+
| **height** | number | height of the background image | `2048` | `False` |
|
|
246
|
+
| **width** | number | width of the background image | `2048` | `False` |
|
|
247
|
+
|
|
248
|
+
``` js
|
|
249
|
+
{
|
|
250
|
+
name: 'histogram unique name',
|
|
251
|
+
theme: 'string characterizing the theme',
|
|
252
|
+
background: {
|
|
253
|
+
url: 'image url',
|
|
254
|
+
radius: 'radius of the background in VR',
|
|
255
|
+
height: 'height',
|
|
256
|
+
width: 'height'
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### NdmVRStorage
|
|
262
|
+
|
|
263
|
+
Service manages offsets and ranges. Data are saved in localstorage for manipulation in next time.
|
|
264
|
+
|
|
265
|
+
- Service provide function for storing offsets:
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
const section = {
|
|
269
|
+
name: 'TH3',
|
|
270
|
+
xOffset: 1,
|
|
271
|
+
yOffset: 1,
|
|
272
|
+
zOffset: 1,
|
|
273
|
+
range: 8
|
|
274
|
+
}
|
|
275
|
+
storeOffsets(section)
|
|
276
|
+
```
|
|
277
|
+
- Service provide function for loading offsets:
|
|
278
|
+
|
|
279
|
+
```js
|
|
280
|
+
loadOffsets('TH3')
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
If the localstorage has stored data, we get returned value represented an object which determines the section.
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
14
287
|
## Usage
|
|
15
288
|
|
|
16
289
|
```jsx
|
|
@@ -26,6 +299,90 @@ class Example extends Component {
|
|
|
26
299
|
}
|
|
27
300
|
```
|
|
28
301
|
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Example
|
|
305
|
+
|
|
306
|
+
The first step is to get the necessary objects that will need to be visualized using the **ndmVrHistogramScene** component. For this purpose, we can use the JSROOT object to create a histogram but also to obtain objects from **ROOT files**.
|
|
307
|
+
|
|
308
|
+
### get object from ***ROOT file***
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
In this case, the url address of the root file is required. We should get all the objects needed for visualization from the file.
|
|
312
|
+
|
|
313
|
+
To load an object, assume that we have a reference to the JSROOT object stored in the jsroot variable, which contains all the necessary functions.
|
|
314
|
+
|
|
315
|
+
```js
|
|
316
|
+
// url root suboru
|
|
317
|
+
let filename = 'https://eos.ndmspc.io/eos/ndmspc/scratch/test/gitlab-hist.root'
|
|
318
|
+
// JSROOT funkcia pre otvorenie súboru, ako návratovú hodnotu ziskavame Promise.
|
|
319
|
+
JSROOT.openFile(filename)
|
|
320
|
+
// ak funkcia otvorí súbor následne dôjde k prečítaniu objektu "main" a vracia sa prečítaný objekt
|
|
321
|
+
.then(file => file.readObject('main'))
|
|
322
|
+
.then(obj => {
|
|
323
|
+
/*
|
|
324
|
+
* V tomto bloku spracujeme samotný objekt
|
|
325
|
+
* Objekt získame ako parameter obj a vieme s ním pracovať
|
|
326
|
+
* Vhodné je uloženie objektu do premennej a nastavenie stavu indikujúceho prístupnosť objektu
|
|
327
|
+
*/
|
|
328
|
+
})
|
|
329
|
+
.catch(error => {
|
|
330
|
+
/*
|
|
331
|
+
* V prípade ak dôjde k chybe vykoná sa tento blok
|
|
332
|
+
*/
|
|
333
|
+
});
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
### Create histogram
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
The JSROOT object also contains functions for creating histograms, this procedure is less recommended due to the fact that creating complex histograms can be difficult for the browser on the client side.
|
|
341
|
+
|
|
342
|
+
Therefore, it is most recommended to create statistics in the ROOT application on a special device and distribute to the client already finished objects in the ROOT file, which are then only loaded and visualized by the client's browser.
|
|
343
|
+
|
|
344
|
+
```js
|
|
345
|
+
// Fragment, ktorý vytvorí histogram TH2I s rozmermi 20x20 a vyplní obsahy binov
|
|
346
|
+
const histo = jsroot.createHistogram('TH2I', 20, 20)
|
|
347
|
+
// Počítadlo
|
|
348
|
+
let cnt = 0;
|
|
349
|
+
// Cykly na zabezpečenie prechodu všetkých binov vytvoreného histogramu
|
|
350
|
+
for (var iy=1;iy<=20;iy++)
|
|
351
|
+
for (var ix=1;ix<=20;ix++) {
|
|
352
|
+
// Získanie konkrétneho objektu binu na základe jeho súradnic v histograme
|
|
353
|
+
var bin = histo.getBin(ix, iy), val = 0;
|
|
354
|
+
val=cnt;
|
|
355
|
+
// Nastavenie hodnoty binu
|
|
356
|
+
histo.setBinContent(bin, val);
|
|
357
|
+
cnt+=0.1;
|
|
358
|
+
}
|
|
359
|
+
// Nastavenie globálnych údajov histogramu
|
|
360
|
+
histo.fXaxis.fTitle = 'x Axis'
|
|
361
|
+
histo.fYaxis.fTitle = 'y Axis'
|
|
362
|
+
histo.fName = "You don't have a valid file path"
|
|
363
|
+
histo.fTitle = "This is a TH2 histogram demo"
|
|
364
|
+
histo.fMaximum = cnt
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
#### Create visualization
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
Ak už sú načítané potrebné objekty v aplikácii, tak je možné histogramy vizualizovať pomocou komponentov **NDMVR**.
|
|
371
|
+
|
|
372
|
+
If the required objects in the application have already been loaded, the histograms can be visualized using the **NDMVR** components.
|
|
373
|
+
|
|
374
|
+
```jsx
|
|
375
|
+
<NdmVrScene data={data} info={info} />
|
|
376
|
+
|
|
377
|
+
...
|
|
378
|
+
|
|
379
|
+
<JSrootHistogram histogram={histograms.physics} projectionAxes={['X','Y']} projections={histograms.projections} projIndex={0}/>
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Components create everything you need. The parameters must be provided to the components as they were in the NDMVR documentation.
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
29
386
|
## License
|
|
30
387
|
|
|
31
388
|
MIT © [NDMSPC](https://gitlab.com/ndmspc/ndmvr)
|