Select to view content in your preferred language

How to assign elevations

5786
30
07-01-2015 07:15 AM
JacquelineAlessi
Frequent Contributor

I do have another question for you afterall. I have brought in a layer of all of the building floors, it contains information about the elevation of the floor of the floor and also has the height of the floor. This is very important because our buildings have irregular interstitials that have been requested to be modled true to form. I was able to create a rule to extrude each floor by the height attribute. Im stuck on trying to determine how to assign the elevations in the attributes as the "heightmap", the elevation that floor should sit on. I want this to be independant of my terrain so I assume that it has to be added to the rule. I found some information online stating that there was a way to do this but the token settings.setHeightmap say that it is undefined. Very confused: below is an example of where Im currently at:

#This attribute should be "sourced" to the object attribute

attr Height = 0

attr Elevation = 0

@StartRule

Lot -->

  extrude (Height)

  volume.

This is the example I atempted to use but I guess I dont understand it:

alignShapes(self, shapes, settings=None)Aligns a set of shapes.

@param shapes: The set of shapes to align.
@param settings: The align settings. Omit to use default settings. (default  = None).

@note: # align shapes of layer 'Lots' to layer 'Heightmap'
lotLayer = ce.getObjectsFrom(ce.scene, ce.isLayer, ce.withName("'Lots'"))
settings = AlignShapesSettings()
settings.setHeightmap('Heightmap')
settings.setAlignFunction(AlignShapesSettings.TRANSLATE_TO_MIN)
ce.alignShapes(lotLayer, settings)

0 Kudos
30 Replies
by Anonymous User
Not applicable

Sorry, this web page wrapped my comments into the next line:

case Elevation >= 700 && Elevation <950:

case Elevation >= 950 && Elevation <1000:

0 Kudos
JacquelineAlessi
Frequent Contributor

So Im not sure if Im doing something wrong but only some of my floors are being identified and the rest arent even registering (the grey should be orange tones). I double checked the individual attributes of each shape and they all fall with in the ranges that I put in. I put a copy of my code below.

attr Height = 0

attr Elevation = 0

@StartRule

BuildingByElevation -->

  t(0,((Elevation)/3.28084),0)

  extrude ((Height)/3.28084)

  comp (f) {all:AllComponents}

AllComponents -->

  case (Elevation >=759 && Elevation <770.52):

  color (255,200,0)

  case (Elevation >=770.52 && Elevation <782.04):

  color (255,187,0)

  case (Elevation >=782.04 && Elevation <793.56):

  color (255,170,0)

  case (Elevation >=793.56 && Elevation <805.08):

  color (255,157,0)

  case (Elevation >=805.08 && Elevation <816.6):

  color (255,140,0)

  case (Elevation >=816.6 && Elevation <828.12):

  color (255,123,8)

  case (Elevation >=828.12 && Elevation <839.64):

  color (255,106,20)

  case (Elevation >=839.64 && Elevation <851.16):

  color (255,87,31)

  case (Elevation >=851.16 && Elevation <862.68):

  color (255,66,41)

  case (Elevation >=862.68 && Elevation <874.2):

  color (255,43,54)

  case (Elevation >=874.2 && Elevation <885.72):

  color (255,0,60)

  case (Elevation >=885.72 && Elevation <897.24):

  color (255,0,72)

  case (Elevation >=897.24 && Elevation <908.76):

  color (255,0,81)

  case (Elevation >=908.76 && Elevation <920.28):

  color (255,0,94)

  case (Elevation >=920.28 && Elevation <931.8):

  color (255,0,106)

  case (Elevation >=931.8 && Elevation <943.32):

  color (255,0,119)

  case (Elevation >=943.32 && Elevation <954.84):

  color (255,0,136)

  case (Elevation >=954.84 && Elevation <966.36):

  color (247,0,153)

  case (Elevation >=966.36 && Elevation <977.88):

  color (230,0,164)

  case (Elevation >=977.88 && Elevation <989.4):

  color (209,0,181)

  case (Elevation >=989.4 && Elevation <1000.92):

  color (183,0,196)

  case (Elevation >=1000.92 && Elevation <1012.44):

  color (157,0,214)

  case (Elevation >=1012.44 && Elevation <1023.96):

  color (126,0,230)

  case (Elevation >=1023.96&& Elevation <1035.48):

  color (85,0,242)

  case (Elevation >=1035.48 && Elevation <1047):

  color (0,0,255)

  else: PrintInfo

0 Kudos
JacquelineAlessi
Frequent Contributor

1047 is a dummy value outside of the range that does not need to be caught.

0 Kudos
JacquelineAlessi
Frequent Contributor

Im thinking that my colors arent translating is there a color chooser I can use? I couldnt find that in the help either.

0 Kudos
JacquelineAlessi
Frequent Contributor

So I translated all of the values to a 0-1 range for RGB instead of a 0-255 range. Im still not understanding why in one of my rules the 0-255 range is respected but in this rule it is only respecting the 0-1 range. What is the method to the madness?

0 Kudos
by Anonymous User
Not applicable

It was a fluke if your 0-255 color worked. Anything over 1 is probably counted as a 1. The function only takes 0 to 1.

There is a version with one parameter (see F1 help). It takes a hex string.

0 Kudos
JacquelineAlessi
Frequent Contributor

Ok that makes perfect sense after looking at the RGB definition in the working rule. Thanks.

0 Kudos
NicolaiSteinø
Regular Contributor

Hi Jacqueline,

Another neat way to solve your problem would be to color your floors by directly using the Y coordinate of your floor in the color() operation. In this example, I have used floor() in order to "step" your color scale. This also allows you to control the number of shades in your color scale by an attribute.

I used the colorRamp() function, but you may of course incorporate this approach directly into color() if you prefer.

This rule would also work for different situations without having to recalculate you case/else steps manually.

Best,

Nic

/**
 * File:    colorByFloor.cga
 * Created: 7 Jul 2015 08:52:51 GMT
 * Author:  Nic
 */

version "2015.0"

attr maxFloorY = 100
attr minFloorY = 0
attr HeightRange = maxFloorY-minFloorY
attr numberOfShades = 20

@Startrule

Lot --> extrude(maxFloorY) split(y) {~3 : Floor }*
Floor --> color(colorRamp("spectrum", (floor(scope.elevation/HeightRange*numberOfShades)/numberOfShades)))

Skærmbillede 2015-07-07 kl. 11.14.27.png

0 Kudos
JacquelineAlessi
Frequent Contributor

Hi Nic, unfortunately this isnt working for my current project. I had to adjust the Elevation information to fit my data. Each floor has its own elevation attribute that it using as a heightmap and the above just places a color ramp on each individual floor. So an 8 story building becomes 8 color ramps in stead of having one color per SD of the elevations. Thats what I need. 25 distinct colors that are defined by 11.5foot SD.

0 Kudos
JacquelineAlessi
Frequent Contributor

Question to both of you:

So I had so much trouble with the original method that I was trying to use so I created a  sin curve spectrum equation from the attributes that I was trying to work with. I am getting an unexpected token error. Im not sure if its because "Color" is a reserved word or not, I thought CGA was case sensitive. Please see the below.

The last line is the one giving me issues. Do I need to define "Color"? Do I need to use set.material to define the color format somewhere?

attr Height = 0

#Elevation is used for generating the model at the correct elevation

#AND

#Assigning the color ramp for the floor elevation

attr Elevation = 0

ElevationMin = 760

ElevationMax = 1050

RepeatBand = 48

PI = 3.14159

Constant = 4.1887902



@StartRule

BuildingByElevation -->

  t(0,((Elevation)/3.28084),0)

  extrude ((Height)/3.28084)

  #You could use:

  #comp (f) {top:Top | side:Side | bottom:Bottom}

  #Because we want all three components to reflect the same rule we can use the all operator instead

  comp (f) {all:AllComponents}

ColorRamp -->

 

AllComponents -->

  Period = (ElevationMax - ElevationMin)/RepeatBand

  Seed = (Elevation - ElevationMin)/(ElevationMax - ElevationMin)

  Red = SIN(PI*Seed*Period)/2+.5)

  Green = SIN(PI*Seed*Period+Constant)/2+.5)

  Blue = SIN(PI*Seed*Period-Constant)/2+.5)

  Color(Red, Green, Blue)

0 Kudos