algo
This commit is contained in:
@@ -120,12 +120,12 @@ class Terrain(ArchComponent.Component):
|
||||
"Surface",
|
||||
"Use a Point Group to generate the surface")
|
||||
|
||||
if not ("Mesh" in pl):
|
||||
if not ("mesh" in pl):
|
||||
obj.addProperty("Mesh::PropertyMeshKernel",
|
||||
"Mesh",
|
||||
"mesh",
|
||||
"Surface",
|
||||
"Mesh")
|
||||
obj.setEditorMode("Mesh", 1)
|
||||
obj.setEditorMode("mesh", 1)
|
||||
|
||||
if not ("InitialMesh" in pl):
|
||||
obj.addProperty("Mesh::PropertyMeshKernel",
|
||||
@@ -156,7 +156,7 @@ class Terrain(ArchComponent.Component):
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
if prop == "InitialMesh":
|
||||
obj.Mesh = obj.InitialMesh.copy()
|
||||
obj.mesh = obj.InitialMesh.copy()
|
||||
|
||||
if prop == "DEM" or prop == "CuttingBoundary":
|
||||
from datetime import datetime
|
||||
@@ -197,11 +197,10 @@ class Terrain(ArchComponent.Component):
|
||||
del templist
|
||||
|
||||
# create xy coordinates
|
||||
import PVPlantSite
|
||||
offset = PVPlantSite.get().Origin
|
||||
x = 1000 * (cellsize * np.arange(nx)[0::coarse_factor] + xllvalue) - offset.x
|
||||
y = 1000 * (cellsize * np.arange(ny)[-1::-1][0::coarse_factor] + yllvalue) - offset.y
|
||||
datavals = 1000 * datavals # - offset.z
|
||||
offset = self.site.Origin
|
||||
x = (cellsize * np.arange(nx)[0::coarse_factor] + xllvalue) * 1000 - offset.x
|
||||
y = (cellsize * np.arange(ny)[-1::-1][0::coarse_factor] + yllvalue) * 1000 - offset.y
|
||||
datavals = datavals * 1000 # Ajuste de altura
|
||||
|
||||
# remove points out of area
|
||||
# 1. coarse:
|
||||
@@ -210,7 +209,6 @@ class Terrain(ArchComponent.Component):
|
||||
inc_y = obj.CuttingBoundary.Shape.BoundBox.YLength * 0.0
|
||||
tmp = np.where(np.logical_and(x >= (obj.CuttingBoundary.Shape.BoundBox.XMin - inc_x),
|
||||
x <= (obj.CuttingBoundary.Shape.BoundBox.XMax + inc_x)))[0]
|
||||
print(tmp)
|
||||
x_max = np.ndarray.max(tmp)
|
||||
x_min = np.ndarray.min(tmp)
|
||||
|
||||
@@ -249,10 +247,10 @@ class Terrain(ArchComponent.Component):
|
||||
pts.append([x[i], y[j], datavals[j][i]])
|
||||
if len(pts) > 3:
|
||||
try:
|
||||
mesh.addMesh(Triangulation.Triangulate(pts))
|
||||
#Mesh.show(mesh)
|
||||
triangulated = Triangulation.Triangulate(pts)
|
||||
mesh.addMesh(triangulated)
|
||||
except TypeError:
|
||||
print("error al procesar: {0} puntos".format(len(pts)))
|
||||
print(f"Error al procesar {len(pts)} puntos: {str(e)}")
|
||||
|
||||
mesh.removeDuplicatedPoints()
|
||||
mesh.removeFoldsOnSurface()
|
||||
@@ -284,12 +282,9 @@ class Terrain(ArchComponent.Component):
|
||||
|
||||
import MeshTools.Triangulation as Triangulation
|
||||
mesh = Triangulation.Triangulate(Data)
|
||||
'''shape = PVPlantCreateTerrainMesh.MeshToShape(mesh)
|
||||
shape.Placement.move(nbase)'''
|
||||
|
||||
obj.Shape = shape
|
||||
if obj.DEM:
|
||||
obj.DEM = None
|
||||
obj.mesh = mesh
|
||||
|
||||
def execute(self, obj):
|
||||
''''''
|
||||
@@ -307,7 +302,6 @@ class ViewProviderTerrain:
|
||||
"A View Provider for the Pipe object"
|
||||
|
||||
def __init__(self, vobj):
|
||||
self.Object = vobj.Object
|
||||
self.boundary_color = None
|
||||
self.edge_style = None
|
||||
self.edge_color = None
|
||||
@@ -321,16 +315,16 @@ class ViewProviderTerrain:
|
||||
# Triangulation properties.
|
||||
pl = vobj.PropertiesList
|
||||
if not ("Transparency" in pl):
|
||||
vobj.addProperty("App::PropertyIntegerConstraint",
|
||||
'''vobj.addProperty("App::PropertyIntegerConstraint",
|
||||
"Transparency",
|
||||
"Surface Style",
|
||||
"Set triangle face transparency").Transparency = (50, 0, 100, 1)
|
||||
"Set triangle face transparency").Transparency = (50, 0, 100, 1)'''
|
||||
|
||||
if not ("ShapeColor" in pl):
|
||||
vobj.addProperty("App::PropertyColor",
|
||||
"ShapeColor",
|
||||
"Surface Style",
|
||||
"Set triangle face color").ShapeColor = (r, g, b, vobj.Transparency / 100)
|
||||
"Set triangle face color").ShapeColor = (0.0, 0.667, 0.49, vobj.Transparency / 100)
|
||||
|
||||
if not ("ShapeMaterial" in pl):
|
||||
vobj.addProperty("App::PropertyMaterial",
|
||||
@@ -413,18 +407,21 @@ class ViewProviderTerrain:
|
||||
"Set major contour line width").MinorWidth = (2.0, 1.0, 20.0, 1.0)
|
||||
|
||||
vobj.Proxy = self
|
||||
self.Object = vobj.Object
|
||||
# Inicializar colores correctamente
|
||||
vobj.ShapeMaterial.DiffuseColor = vobj.ShapeColor
|
||||
|
||||
def onDocumentRestored(self, vobj):
|
||||
self.setProperties(vobj)
|
||||
|
||||
def onChanged(self, vobj, prop):
|
||||
''' Update Object visuals when a view property changed. '''
|
||||
""" Update Object visuals when a view property changed. """
|
||||
|
||||
if prop == "ShapeColor" or prop == "Transparency":
|
||||
if hasattr(vobj, "ShapeColor") and hasattr(vobj, "Transparency"):
|
||||
color = vobj.getPropertyByName("ShapeColor")
|
||||
transparency = vobj.getPropertyByName("Transparency")
|
||||
color = (color[0], color[1], color[2], transparency / 100)
|
||||
color = (color[0], color[1], color[2], 50 / 100)
|
||||
vobj.ShapeMaterial.DiffuseColor = color
|
||||
|
||||
if prop == "ShapeMaterial":
|
||||
@@ -555,7 +552,7 @@ class ViewProviderTerrain:
|
||||
highlight.addChild(mat_binding)
|
||||
highlight.addChild(self.geo_coords)
|
||||
highlight.addChild(self.triangles)
|
||||
highlight.addChild(boundaries)
|
||||
#highlight.addChild(boundaries)
|
||||
|
||||
# Face root.
|
||||
face = coin.SoSeparator()
|
||||
@@ -573,14 +570,14 @@ class ViewProviderTerrain:
|
||||
surface_root.addChild(face)
|
||||
surface_root.addChild(offset)
|
||||
surface_root.addChild(edge)
|
||||
surface_root.addChild(major_contours)
|
||||
surface_root.addChild(minor_contours)
|
||||
#surface_root.addChild(major_contours)
|
||||
#surface_root.addChild(minor_contours)
|
||||
vobj.addDisplayMode(surface_root, "Surface")
|
||||
|
||||
# Boundary root.
|
||||
boundary_root = coin.SoSeparator()
|
||||
boundary_root.addChild(boundaries)
|
||||
vobj.addDisplayMode(boundary_root, "Boundary")
|
||||
#boundary_root = coin.SoSeparator()
|
||||
#boundary_root.addChild(boundaries)
|
||||
#vobj.addDisplayMode(boundary_root, "Boundary")
|
||||
|
||||
# Elevation/Shaded root.
|
||||
'''shaded_root = coin.SoSeparator()
|
||||
@@ -599,8 +596,8 @@ class ViewProviderTerrain:
|
||||
# Wireframe root.
|
||||
wireframe_root = coin.SoSeparator()
|
||||
wireframe_root.addChild(edge)
|
||||
wireframe_root.addChild(major_contours)
|
||||
wireframe_root.addChild(minor_contours)
|
||||
#wireframe_root.addChild(major_contours)
|
||||
#wireframe_root.addChild(minor_contours)
|
||||
vobj.addDisplayMode(wireframe_root, "Wireframe")
|
||||
|
||||
# Take features from properties.
|
||||
@@ -629,19 +626,19 @@ class ViewProviderTerrain:
|
||||
'''
|
||||
|
||||
if prop == "Mesh":
|
||||
print("update terrain mesh")
|
||||
mesh = obj.Mesh
|
||||
copy_mesh = mesh.copy()
|
||||
# copy_mesh.Placement.move(origin.Origin)
|
||||
if obj.mesh:
|
||||
print("Mostrar mesh")
|
||||
|
||||
triangles = []
|
||||
for i in copy_mesh.Topology[1]:
|
||||
triangles.extend(list(i))
|
||||
triangles.append(-1)
|
||||
mesh = obj.mesh
|
||||
vertices = [tuple(v) for v in mesh.Topology[0]]
|
||||
faces = []
|
||||
for face in mesh.Topology[1]:
|
||||
faces.extend(face)
|
||||
faces.append(-1)
|
||||
|
||||
self.geo_coords.point.values = copy_mesh.Topology[0]
|
||||
self.triangles.coordIndex.values = triangles
|
||||
del copy_mesh
|
||||
# Asignar a los nodos de visualización
|
||||
self.geo_coords.point.values = vertices # <-- ¡Clave!
|
||||
self.triangles.coordIndex.values = faces # <-- ¡Clave!
|
||||
|
||||
def getDisplayModes(self, vobj):
|
||||
''' Return a list of display modes. '''
|
||||
@@ -656,7 +653,9 @@ class ViewProviderTerrain:
|
||||
return "Surface"
|
||||
|
||||
def claimChildren(self):
|
||||
return [self.Object.CuttingBoundary, ]
|
||||
if hasattr(self, "Object") and self.Object:
|
||||
return [self.Object.CuttingBoundary, ]
|
||||
return []
|
||||
|
||||
def getIcon(self):
|
||||
return str(os.path.join(DirIcons, "terrain.svg"))
|
||||
|
||||
Reference in New Issue
Block a user