File: compute_barycenter.py

package info (click to toggle)
camitk 6.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 389,496 kB
  • sloc: cpp: 103,476; sh: 2,448; python: 1,618; xml: 984; makefile: 128; perl: 84; sed: 20
file content (24 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
import camitk

def init(self:camitk.Action):
    camitk.info("CamiTK version: " + camitk.__version__)
    camitk.info("Opened components before: " + str(len(camitk.Application.getTopLevelComponents())))
    camitk.Application.open(camitk.Core.getTestDataDir() + "/sinus_skin.vtk")
    camitk.info("Opened components after: " + str(len(camitk.Application.getTopLevelComponents())))
    for c in camitk.Application.getTopLevelComponents():
        print(c.getName()) # print will print to CamiTK console without timestamp, level and location in code    

def compute_barycenter(self):
    points = self.getTargets()[-1].getPointSetAsNumpy()
    barycenter = np.mean(points, axis=0)
    self.setParameterValue("Barycenter", "QVector3D(" + str(barycenter[0]) + "," + str(barycenter[1]) + "," + str(barycenter[2]) +")")
    return points, barycenter

def targetDefined(self:camitk.Action):
    compute_barycenter(self)

def process(self:camitk.Action):
    points, barycenter = compute_barycenter(self)

    return True