-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathproperty.go
81 lines (65 loc) · 2.05 KB
/
property.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package ply
import (
"fmt"
"io"
)
type Property interface {
Name() string // Name of the property as found in the PLY header
Write(out io.Writer) error // Writes out the definition of the property in PLY format
}
type ScalarPropertyType string
const (
Char ScalarPropertyType = "char"
UChar ScalarPropertyType = "uchar" // uint8
Short ScalarPropertyType = "short"
UShort ScalarPropertyType = "ushort"
Int ScalarPropertyType = "int"
UInt ScalarPropertyType = "uint"
Float ScalarPropertyType = "float"
Double ScalarPropertyType = "double"
)
func (spt ScalarPropertyType) Size() int {
switch spt {
case Char, UChar:
return 1
case Short, UShort:
return 2
case Int, UInt, Float:
return 4
case Double:
return 8
default:
panic(fmt.Errorf("unimplemented byte size for scalar property type: %s", spt))
}
}
type ScalarProperty struct {
PropertyName string `json:"name"` // Name of the property
Type ScalarPropertyType `json:"type"` // Property type
}
// Name of the property as found in the PLY header
func (sp ScalarProperty) Name() string {
return sp.PropertyName
}
// Size of the property on a per point basis when serialized to binary format
func (sp ScalarProperty) Size() int {
return sp.Type.Size()
}
// Writes out the definition of the property in PLY format
func (sp ScalarProperty) Write(out io.Writer) (err error) {
_, err = fmt.Fprintf(out, "property %s %s\n", sp.Type, sp.PropertyName)
return
}
type ListProperty struct {
PropertyName string // Name of the property
CountType ScalarPropertyType // Data type of the number used to define how many elements are in the list
ListType ScalarPropertyType // Data type of the elements in the list
}
// Name of the property as found in the PLY header
func (lp ListProperty) Name() string {
return lp.PropertyName
}
// Writes out the definition of the property in PLY format
func (lp ListProperty) Write(out io.Writer) (err error) {
_, err = fmt.Fprintf(out, "property list %s %s %s\n", lp.CountType, lp.ListType, lp.PropertyName)
return
}