sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Code] Image: definition, transformation, transformation=

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 6 Posters 4.5k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      tomasz
      last edited by

      @chris fullmer said:

      What about looking at the edge loop .reversed_in? method or something? Will that help somehow?

      I have tried it, but it doesn't work. Loop of the edges is in its 'untransformed' state stored in a image definition.

      I am afraid that there is no way around it.

      Btw. I didn't know, before I examined an image, that it is a 'special' ComponentDefinition (containing a face and four edges).

      Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

      1 Reply Last reply Reply Quote 0
      • T Offline
        tomasz
        last edited by

        Is there a way to get all objects that has a vertex in a given point?

        We could check whether there is the same image in a location of all face vertexes (after transformation), if not then the component would need to be flipped.

        Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

        1 Reply Last reply Reply Quote 0
        • C Offline
          Cleverbeans
          last edited by

          I believe you can detect a negative scaling by checking the determinant of the upper left 3x3 block matrix since all negative scalings have negative determinants unless they are simply a rotation. Here is some code.

          
          def isflipped?(tr)
              m = tr.to_a()
              det = m[0]*m[5]*m[10] + m[1]*m[6]*m[8] + m[2]*m[4]*m[9] - m[2]*m[5]*m[8] - m[0]*m[6]*m[9] - m[1]*m[4]*m[10]
              if det < 0 then
                  return true
              end
              return false
          end
          
          

          Let me know if that detects the transformations you're trying to modify. However I think there is a built in ambiguity here, if you're going to interpret negative scaling as a "flip" then what direction are you flipping? I think you could rotate the image around either of the two center lines and achieve a flip but then the question is which one would you expect when you do a -1 scaling transformation? Can you clarify how the current behavior differs from the expected behavior?

          1 Reply Last reply Reply Quote 0
          • T Offline
            tomasz
            last edited by

            @cleverbeans said:

            Let me know if that detects the transformations you're trying to modify.

            The problem actually is to get the flipped transformation. The method always returns not flipped state.
            It would be nice if the self.width or self.height would return negative values.

            Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

            1 Reply Last reply Reply Quote 0
            • C Offline
              Cleverbeans
              last edited by

              So the trouble is to get the transformation which will flip the image? Does this transformation give the behavior you're looking for? If so, do you want a transform constructed by Geom::Transformation.scaling(-1) method to produce the same behavior as this transform?

              tr = Geom;;Transformation.new([-1,0,0,0,0,-1,0,0,0,0,-1,0,0,0,0,1])
              
              1 Reply Last reply Reply Quote 0
              • T Offline
                tomasz
                last edited by

                The question is : Flip or not to flip and which axis? I am afraid we have no way to figure it out from Ruby alone.
                Flipped.jpg
                The image in the SU is flipped vertically. The transformation returned from the method will have no negative scaling along Z axis, which results in an image placed in a position marked with hidden lines.

                Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  You can get a transformation's scaling along each axis thus
                  [where 'tr' is the object's transformation object]

                  
                  def scaleX(tr)
                    Math.sqrt(tr.to_a[0]**2+tr.to_a[1]**2+tr.to_a[2]**2)
                  end
                  def scaleY(tr)
                    Math.sqrt(tr.to_a[4]**2+tr.to_a[5]**2+tr.to_a[6]**2)
                  end
                  def scaleZ(tr)
                    Math.sqrt(tr.to_a[8]**2+tr.to_a[9]**2+tr.to_a[10]**2)
                  end
                  
                  

                  This will NOT show the 'handing' BUT this should...

                  
                  def flippedX?(tr)
                    return true if tr.to_a[0] < 0
                    return false
                  end
                  def flippedY?(tr)
                    return true if tr.to_a[5] < 0
                    return false
                  end
                  def flippedZ?(tr)
                    return true if tr.to_a[10] < 0
                    return false
                  end
                  
                  

                  I think πŸ˜• - try and see - there is a way even if I've messed this up!

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    Cleverbeans
                    last edited by

                    I think the methods TIG described gives the right idea, however I'm not sure there is a problem with the code as provided. It seems as though you can transform the image in any meaningful way with a correctly articulated transform, and if it is not "working" as the user expects that be an issue with the user's understanding of how transforms work rather than with the code itself.

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @unknownuser said:

                      @cleverbeans said:

                      Let me know if that detects the transformations you're trying to modify.

                      The problem actually is to get the flipped transformation. The method always returns not flipped state.
                      It would be nice if the self.width or self.height would return negative values.

                      Did you find a solution that worked?

                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        tomasz
                        last edited by

                        As a 'Thanks!' to Alex and my contribution to wellness of other exporters and especially their developers πŸ˜„ here is my modified transformation method that works I think in 99.9%. It may fail due to float precision, but I looks it doesn't happen too often.

                        My idea is to calculate a center of the image, based on initially derived transformation and to compare it with a center of bounding box of the instance self.bounds.center. If the points are not same it means that an image is flipped.

                        If flipped, I create a modified transformation with a negative scaling along y axis.

                        Now I realized that this can be done by simply crating a Geom::Transformation.scaling origin, 1, -1, 1 and applying it to the original trans...

                        	def transformation
                        		origin = self.origin
                        		axes = self.normal.axes
                        		tr = Geom;;Transformation.axes(ORIGIN, axes.x, axes.y, axes.z)
                        		tr = tr * Geom;;Transformation.rotation(ORIGIN, Z_AXIS, self.zrotation)
                        		tr = tr * Geom;;Transformation.scaling(ORIGIN, self.width/self.pixelwidth, self.height/self.pixelheight,1)
                        		tr=tr.to_a
                        		tr[12]=origin.x
                        		tr[13]=origin.y
                        		tr[14]=origin.z
                        		trans = Geom;;Transformation.new(tr) #Global! trans of an image instance
                        
                        		#check if flipped
                        		center_point=Geom;;Point3d.new(self.pixelwidth/2.0,self.pixelheight/2.0,0).transform! trans #center of an image
                        		center=self.bounds.center
                        		flipped=(center_point.x!=center.x or center_point.y!=center.y or center_point.z!=center.z)
                        
                        		if flipped
                        			tr = Geom;;Transformation.axes(ORIGIN, axes.x, axes.y, axes.z)
                        			tr = tr * Geom;;Transformation.rotation(ORIGIN, Z_AXIS, self.zrotation)
                        			tr = tr * Geom;;Transformation.scaling(ORIGIN, self.width/self.pixelwidth, -self.height/self.pixelheight,1)
                        			tr=tr.to_a
                        			tr[12]=origin.x
                        			tr[13]=origin.y
                        			tr[14]=origin.z
                        			trans = Geom;;Transformation.new(tr)
                        		end
                        		return trans
                        	end#def
                        

                        Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement