本文整理汇总了Python中Point.Point.get_position方法的典型用法代码示例。如果您正苦于以下问题:Python Point.get_position方法的具体用法?Python Point.get_position怎么用?Python Point.get_position使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point.Point
的用法示例。
在下文中一共展示了Point.get_position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AbstractVoxel
# 需要导入模块: from Point import Point [as 别名]
# 或者: from Point.Point import get_position [as 别名]
class AbstractVoxel(object): # todo reimplement with PYTHON way of defining abstract classes!
# triggers the behavior of the voxel class, if datapoints for the voxel do not exist
_create_datapoints_if_they_do_not_exist = True
_dimension = None
_voxel_edge_manager = None
_voxel_verts = None
_voxel_edges = None
_vertex_mode = "MEAN_VALUE_MODE"
_look_up_mode = "LAZY"
def __init__(self, origin, edge_length, dataset):
self._origin = Point(origin)
self._edge_length = edge_length
self._dataset = dataset
self._set_voxel_datapoints()
self._set_voxel_dataedges()
self._dc_vertices = []
def get_origin(self):
return self._origin.get_position()
def get_dc_vertices(self):
return self._dc_vertices
def _set_voxel_datapoints(self):
self._voxel_datapoints = {}
for local_id, vec_origin_corner in self.__class__._voxel_verts.items():
corner_position = self._origin.get_position() + self._edge_length * vec_origin_corner
if self._dataset.datapoint_at_exists(corner_position):
self._voxel_datapoints[local_id] = self._dataset.get_datapoint_at(corner_position)
elif self._create_datapoints_if_they_do_not_exist:
self._dataset.add_datapoint(corner_position, False)
self._voxel_datapoints[local_id] = self._dataset.get_datapoint_at(corner_position)
else:
expt_str = (
"class __AbstractVoxel::__set_voxel_data\n\tDatapoint at "
+ str(corner_position)
+ "does not exist!"
)
raise Exception(expt_str)
def _set_voxel_dataedges(self):
self._voxel_dataedges = {}
for local_id, local_edge_key in self.__class__._voxel_edges.items():
datapoints = 2 * [None]
for i in range(2):
datapoints[i] = self._voxel_datapoints[local_edge_key[i]]
self._voxel_dataedges[local_id] = self.__class__._voxel_edge_manager.get_voxel_edge(
self._edge_length, datapoints
)
def get_signs(self):
signs = {}
for local_id, datapoint in self._voxel_datapoints.items():
value = self._voxel_datapoints[local_id].get_value()
if isinstance(value, bool):
signs[local_id] = value
elif isinstance(value, float):
signs[local_id] = value < 0
else:
raise Exception("class __AbstractVoxel::get_signs\n\tinvalid value format in datapoint!")
return signs
def get_gradients(self):
gradients = {}
for local_id, dp in self._voxel_datapoints.items():
gradients[local_id] = self._estimate_gradient_on_vertex(local_id)
return gradients
def _get_middle_position(self):
displacement = np.ones(self.__class__._dimension)
return self._origin.get_position() + self._edge_length / 2 * displacement
def _get_middle_point(self):
middle_position = self._get_middle_position()
return self._dataset.get_datapoint_at(middle_position)
def _estimate_gradient_on_vertex(self, local_id):
neighbor_disps = [np.array([1, 1]), np.array([-1, -1]), np.array([-1, 1]), np.array([1, -1])]
point = self._voxel_datapoints[local_id]
gradient = np.zeros(2)
for neighbor_disp in neighbor_disps:
neighbor_pos = point.get_position() + self._edge_length / 2.0 * neighbor_disp
neighbor = self._dataset.get_datapoint_at(neighbor_pos)
if neighbor is not None:
gradient += (float(neighbor.get_value()) - float(point.get_value())) * neighbor_disp
return gradient / 4.0
def _get_sign_change_edges(self):
sign_change_edges = set()
signs = self.get_signs()
#.........这里部分代码省略.........