1
|
|
|
#!/usr/bin/env python2.7 |
2
|
|
|
"""Apply transformation to pointcloud. |
3
|
|
|
|
4
|
|
|
The transformations (if given) are applied in the following order: |
5
|
|
|
1. rotation |
6
|
|
|
2. scaling |
7
|
|
|
3. offset |
8
|
|
|
|
9
|
|
|
Usage: |
10
|
|
|
transform.py [-o <origin>] [-r <rot>] [-t <translate>] [-s <scaling>] <source> <target> |
|
|
|
|
11
|
|
|
|
12
|
|
|
Positional arguments: |
13
|
|
|
source Source pointcloud file |
14
|
|
|
target Target pointcloud file |
15
|
|
|
|
16
|
|
|
Options: |
17
|
|
|
-r <rot> CSV file of a 4x4 transformation matrix, assumed to be |
18
|
|
|
normalized. |
19
|
|
|
-o <rot_origin> CSV file with a 3d point of the origin for the |
20
|
|
|
rotation and scaling |
21
|
|
|
-s <scaling> CSV file with a single scaling multiplication factor. |
22
|
|
|
-t <translate> CSV file with a 3d vector to translate the pointcloud with. |
23
|
|
|
""" |
24
|
|
|
|
25
|
|
|
from __future__ import print_function |
26
|
|
|
from docopt import docopt |
27
|
|
|
|
28
|
|
|
import numpy as np |
29
|
|
|
from patty.utils import load, save |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
def csv_read(path): |
33
|
|
|
return np.genfromtxt(path, dtype=float, delimiter=',') |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
if __name__ == '__main__': |
37
|
|
|
args = docopt(__doc__) |
|
|
|
|
38
|
|
|
|
39
|
|
|
pc = load(args['<source>']) |
|
|
|
|
40
|
|
|
|
41
|
|
|
try: |
42
|
|
|
offset = csv_read(args['-o']) |
|
|
|
|
43
|
|
|
except: |
44
|
|
|
offset = None |
|
|
|
|
45
|
|
|
|
46
|
|
|
try: |
47
|
|
|
matrix = csv_read(args['-r']) |
|
|
|
|
48
|
|
|
pc.rotate(matrix, origin=offset) |
49
|
|
|
except Exception as e: |
|
|
|
|
50
|
|
|
print('Problem with rotate: ', e) |
51
|
|
|
|
52
|
|
|
try: |
53
|
|
|
factor = csv_read(args['-s']) |
|
|
|
|
54
|
|
|
pc.scale(factor, origin=offset) |
55
|
|
|
except Exception as e: |
|
|
|
|
56
|
|
|
print('Problem with scale: ', e) |
57
|
|
|
|
58
|
|
|
try: |
59
|
|
|
vector = csv_read(args['-t']) |
|
|
|
|
60
|
|
|
pc.translate(vector) |
61
|
|
|
except Exception as e: |
|
|
|
|
62
|
|
|
print('Problem with translate: ', e) |
63
|
|
|
|
64
|
|
|
save(pc, args['<target>']) |
65
|
|
|
|
This check looks for lines that are too long. You can specify the maximum line length.