3from numpy.core.numeric
import full
8from numpy.testing._private.utils
import integer_repr
16 nb_list.append(float(i))
18 exit(
"coords and orientation require 3 numbers: x,y,z")
23 return not file.endswith(
'vtk')
28 a, b = (vec1 / np.linalg.norm(vec1)).reshape(3), (vec2 /
29 np.linalg.norm(vec2)).reshape(3)
34 return np.array([0, 0, 0])
35 kmat = np.array([[0, -v[2], v[1]], [v[2], 0, -v[0]], [-v[1], v[0], 0]])
36 R = np.eye(3) + kmat + kmat.dot(kmat) * ((1 - c) / (s ** 2))
38 sy = np.sqrt(R[0, 0] * R[0, 0] + R[1, 0] * R[1, 0])
39 angle0 = np.arctan2(R[2, 1], R[2, 2]) * 180 / np.pi
40 angle1 = np.arctan2(-R[2, 0], sy) * 180 / np.pi
41 angle2 = np.arctan2(R[1, 0], R[0, 0]) * 180 / np.pi
43 return np.array([angle0, angle1, angle2])
47 orientation_np = np.array(orientation)
48 scale = np.linalg.norm(orientation_np)
49 norm_orientation = orientation_np / scale
51 full_h = radius1 / np.tan(angle * np.pi / 180)
52 new_origin = origin + norm_orientation * (full_h - height) / 2.
53 body_test = pv.Cone(center=new_origin, direction=orientation, height=full_h, radius=radius1, capping=
False, angle=
None, resolution=resolution)
54 cut_origin = origin + norm_orientation * (height / 2.)
55 slice = body_test.slice(normal=orientation,origin=cut_origin, generate_triangles=
True)
56 slice = pv.PolyData(slice.points).delaunay_2d()
57 body_test = body_test.clip(normal=orientation, origin=cut_origin, invert=
True)
58 body = pv.MultiBlock([body_test, slice]).combine()
91 self.
height = roller_data[2]
if not np.isinf(roller_data[2])
else self.
radius1 * 3
92 self.
angle = roller_data[3]
99 scale = np.linalg.norm(orientation_np)
100 normz_orien = orientation_np / scale
108 body = pv.Sphere(center=origin, radius=self.
radius1, phi_resolution=self.
resolution)
111 body1 = pv.ParametricTorus(ringradius=pyvista_radius, crosssectionradius=self.
inner_radius)
112 body2 = pv.Cylinder(center=[0,0,0], direction=[0, 0, 1], radius=pyvista_radius,
114 roller = [body1, body2]
115 body = pv.MultiBlock(roller).combine()
120 body.rotate_x(angles[0])
121 body.rotate_y(angles[1])
122 body.rotate_z(angles[2])
124 transform_matrix = np.array(
125 [[1, 0, 0, origin[0]], [0, 1, 0, origin[1]], [0, 0, 1, origin[2]], [0, 0, 0, 1]])
126 body.transform(transform_matrix, inplace=
True)
130 j_resolution=self.
resolution, i_size=scale, j_size=scale)
139 body1 = pv.ParametricTorus(ringradius=pyvista_radius, crosssectionradius=self.
inner_radius)
141 body1.rotate_x(angles[0])
142 body1.rotate_y(angles[1])
143 body1.rotate_z(angles[2])
144 transform_matrix = np.array(
145 [[1, 0, 0, origin[0]], [0, 1, 0, origin[1]], [0, 0, 1, origin[2]], [0, 0, 0, 1]])
146 body1.transform(transform_matrix, inplace=
True)
149 slope_a = np.tan(self.
angle_a * np.pi / 180)
150 offset_a = (self.
inner_radius * slope_a / np.sqrt(1 + slope_a * slope_a)) + self.
height / 2
151 new_origin = origin + normz_orien * offset_a
152 cone_rad = pyvista_radius + self.
inner_radius / np.sqrt(1 + slope_a * slope_a)
156 slope_b = np.tan(self.
angle_b * np.pi / 180)
157 offset_b = (self.
inner_radius * slope_b / np.sqrt(1 + slope_b * slope_b)) + self.
height / 2
158 new_origin = origin - normz_orien * offset_b
159 cone_rad = pyvista_radius + self.
inner_radius / np.sqrt(1 + slope_b * slope_b)
160 orientation_flip = normz_orien * -1
162 body = pv.MultiBlock([body1, body2, body3]).combine()
164 exit(
"this body type is not supported")
171if __name__ ==
'__main__':
176 rigid_bodies_dict = {}
178 if "-resolution" in sys.argv:
179 resolution = int(sys.argv[sys.argv.index(
"-resolution") + 1])
244 parser = argparse.ArgumentParser(
245 description=
"Convert multiple vtk roller files to vtk with rollers geometry", add_help=
False)
247 "-file_name", help=
"list of vtk files or a regexp mask", nargs=
'+')
248 args, unknown = parser.parse_known_args()
250 args.file_name.sort(key=os.path.getmtime)
255 for file
in args.file_name:
256 file_vtu = os.path.splitext(file)[0] +
".vtu"
257 if os.path.exists(file_vtu):
258 if os.path.getmtime(file) < os.path.getmtime(file_vtu):
259 print(
"skipping {} file".format(file))
261 print(
"Processing " + file +
" file.")
262 if not file.endswith(
'vtk'):
263 exit(
"Provide vtk file or files (-file_name)")
272 for point
in mesh.points:
274 id_array = mesh[
'_ROLLER_ID'][index]
275 body_type_id = mesh[
'_BODY_TYPE'][index]
276 orientation_vec = mesh[
'_ORIENTATION'][index]
277 roller_data = mesh[
'_ROLLER_DATA'][index]
280 rigid_body.resolution = resolution
281 rigid_body.set_body_data_from_vertex(body_type_id, orientation_vec, roller_data);
285 all_bodies.append(rigid_body.get_body(point))
288 mesh = pv.MultiBlock(all_bodies).combine()
289 mesh.save(file[:-4] +
".vtu")
if(!static_cast< bool >(ifstream(param_file)))
def get_body(self, origin)
def set_body_data_from_vertex(self, body_type_id, orientation_vec, roller_data)
def split_string_to_vector3(txt)
def get_capped_cone(origin, orientation, radius1, angle, height, resolution)
def get_euler_angles_from_vectors(vec1, vec2)