Rotate array

Hello!
We have an 1Darray with values and we want to rotate/shift the values (3 positions). But everytime it shifts we want to read the array.
For example : we have [1 2 3 4 5 6 7 8 9 10 ] and we want to shift it 3 positions like [10 9 8 1 2 3 4 5 6 7] we want to send this array, read it and then to rotate and read it every time until we get the first array.
Do we have to use loops or we can set it directly?
Any answers are welcome!
Thank You!
Solved!
Go to Solution.

Why do people always insist on making things way more complicated than it needs to be...
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
Rotate and send.png ‏17 KB

Similar Messages

  • 3-D Array

    Ok so I have a ThreeDObject interface which is implemented by my ArrayShape Class which is extended by my LShape class. Well I thought I had done everything correctly, but when I try to test it in my driver I get an error saying the my LShape Constructor is undefined. I cannot find where I am making a mistake at. Please let me know if anyone can spot out what is wrong. Thanks. Here is my code:
    This is my ArrayShape Class
    public abstract class ArrayShape implements ThreeDObject {
         protected int [][][] _shape = new int [4][4][4];
         protected int [][][] _rotation = new int [4][4][4];
         protected Dimension3D _d3d;
         public ArrayShape(int height, int width, int depth){
              _d3d = new Dimension3D(height, width, depth);
         /* (non-Javadoc)
          * @see ThreeDObject#changeView(ThreeDObject.ViewPoint)
         public void changeView(ViewPoint view) {
              // TODO Auto-generated method stub
         /* (non-Javadoc)
          * @see ThreeDObject#getDimension()
         public Dimension3D getDimension() {
              // TODO Auto-generated method stub
              return null;
         /* (non-Javadoc)
          * @see ThreeDObject#rotate(ThreeDObject.RotateDirection)
         public void rotate(RotateDirection dir) {
              int height = _d3d.getHeight();
              int width = _d3d.getWidth();
              int depth = _d3d.getDepth();
              if(dir == RotateDirection.CW){
                   _rotation [width][height][depth] = _shape [height][width][depth];
              if(dir == RotateDirection.CCW){
                   _rotation [width][height][depth] = _shape [height][width][depth];
              // TODO Auto-generated method stub
    }This is my LShape Class
    public class LShape extends ArrayShape{
         public LShape(int height, int width, int depth){
              super(height, width, depth);
              _shape[0][0][0] = 1;
              _shape[0][1][0] = 2;
              _shape[0][2][0] = 3;
              _shape[1][0][0] = 4;
    }and this is my Driver class
    public class ArrayShapeDriver {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              ThreeDObject l = new LShape();
    }

    Ok I am trying to create the 5 tetris shapes. The I, L, Z, T, and the Block. For each shape I want to fill the _shape array:
    1
    2
    34
    12
    34
    so that is the representation that I would want in the array for the LShape and the Block shape. After I have the shape array I want to be able to fill my rotation array with the _shape array. That way when I have to do rotations and View Point changes I can rotate the array as a whole instead of having to flip the idex spots within the array. Im not sure if this makes sense hopefully it does.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Acrobat 3D- PDF's in Flash

    It's in my biggest interest to let my users view my 3d-models using Flash Player, while maintenancing the interactivity. Is this possible to do?
    Benefits:
    1) "Everybody's got Flash Player installed"
    2) You can embed an interactive 3D-model direct into a webpage.
    As far as I know, you can't embed a pdf into a webpage like you can with a swf.
    - Jon

    Displaying a 3D viewport via Flash Player is not going to happen yet. Although FP10 is promoted as having "3D features" it's strictly a 2.5D kernel - there's no internal concept of Z-space, just perspective and rotation arrays to make it look like there is. Dropping a U3D or OBJ into a Flash timeline would be nice, but you'll have to wait.
    Meanwhile, Acrobat 9 can do it perfectly happily, and R9 penetration is quite good - not as deep as FP, but it's a different demographic. People who use the Web for CAD-type business will almost certainly have it, but a kid surfing for games may not. It's also extremely simple to handle legacy visitors to a page with embedded 3D PDF content; we've been doing it since 8.5 launched and our server logs currently run at around 65% having R9 on arrival, and 15% installing it and coming back.
    There are other 3D browser plugins and OS applets such as Right Hemisphere's Deep View, but in general visitors get the point of installing R9 as they've heard of Adobe. Pushing them to another install, however good and safe it may be, is far harder if they don't recognize the name. You also have the advantage that it's a lot more work to drag your original model out from a PDF, whereas some of the third-party viewers simply push the raw mesh file to the visitor.

  • Infinite waveform graph

    I have a monitoring tool (using LV v6.5), that outputs several 1D waveform charts.  Data is pumped into them continuously for hours.  Well, after about 14 hrs, all memory of the Windows PC was expended and the system hung.  Is there a way that I can limit how much data LabView keeps in memory for the chart (occasionally, we save the data to a file so I don't mind if I lose some realtime data)?

    Hi,
    As a quick example of how to implement this using a preallocated array and a graph instead of a chart, see the following snippet which implements two different behaviors of displaying the data.
    To change the direction of the Continuous Update Graph, change the -1 to a 1 on the rotate array. 
    Regarding your statement about the memory usage of the waveform chart: the memory for the waveform chart is allocated at runtime , so it should not be growing in memory usage. If you can attach a sample VI where you see this behavior of the memory usage growing quickly (500 byes per point is very significant) I will look into whether it is a possible CAR. One other thing to consider when using waveform charts for large data sets is the following knowledge base about why you should limit your chart history size.
    I hope that is helpful,
    Regards,

  • Log Alarm Only Once

    Hi everyone,
    I have an interesting issue with logging a 'thermocouple disconnected' alarm as part of a condition monitoring application.
    I am logging thermocouple readings at 5 Hz  when a thermocouple becomes disconnected the reading rises to 1372, which is detected and should sound an alarm.  The application builds a string at this time (and publishes to a table) telling the user which thermocouple has disconnected, and any action undertaken (for example, turning the heater off).
    I would usually include a snippet, although the code uses property nodes (as the error log code is in another loop) making it pretty much unreadable.
    My issue is that the alarm is published on every iteration.  I need to keep checking for other thermocouple failures but disable one which has already occured.  I thought about setting a 'already written' variable in a shift register for each error case but this was getting messy quickly.
    Any help (or ideas of a better way to do this!) are appreciated,
    Pete
    Regards,
    Peter D
    Solved!
    Go to Solution.

    egraham wrote:
    One method still appears faster and I wonder why this faster method isn't the one we should be using???
    Because your method is not the fastest.
    Yes, I was sloppy in my code and there was an additional buffer allocation due to the autoindexing branch of the array. If we index inside the inner for loop, we eliminate that extra buffer allocation and speed it up by more than a factor of two. (I did the autoindex for quicker coding and cleaner diagram, because it does not really matter in your application).
    Also, don't underestimate the new compiler. For some reason your "delete..insert" does not cause a buffer allocation, something that might not be guaranteed in all cases. (tools...profile...show buffer allocations). It might also well be different on older LabVIEW versions. (I have not tried). It might also be different on different CPUs (My times are quite slow because they were done on a very old Athlon XP).
    First, let's make sure we benchmark the right code. We don't do a single replacement as in your benchmark, but there is also an outer shift register where we keep the rotated array. You should also disable debugging, because loops have more debugging overhead, skewing the results.
    Attached is a simple draft with 5 code alternatives. Just run and select one algorithm at a time via the enum selector. The time in ms will be graphed. (There are probably some bugs, please verify correct operation).
    Loop In Place: Using a loop and the "in place element" structure to rotate rows down.
    Loop Original: Using a loop and the proper inner indexing.
    Loop_autoindex: Same as (2) but with autoidenxing, causing a second buffer allocation.
    Delete_Insert: Your code (delete last, insert new element at the beginning).
    Insert_Delete: Basically same as (4) but with operations reversed.
    Here are my results: algorithm incremeneted every 40 iterations)
     (1) and (2) are fastest, (3) is slowest, and (4)&(5) are somewhere in the middle, or about half he speed of the first two.
    Feel free to find a fster method for the same task. There problaby is......
    Also note that the real case has a 2D array of strings, so things might again be slighly different (not tested).
    Just some food for thought....
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    shift array elements_compare5Algorithm.vi ‏22 KB
    ShiftArrayBenchmark.PNG ‏18 KB

  • Load SVGZ Files in JavaFx2.0 and rasterize them

    Hi!
    I wanted to load via Java/JavaFx2.0 a .svgz file and rasterize it. Maybe someone got a clue?
    Thanks for your answers in advance! My ideas up to now were to load them somehow with the batik lib via this code:
    http://stackoverflow.com/questions/6854601/load-svg-file-in-javafx-2-0
    ... but I'm not sure.
    Greetings!

    Hi, it depends if you satisfied with having a SVG being transfered into an image and show this or if you want to have real JavaFX-node-objects. For the first one, there are some solutitons for the second one I have been fouling around with transfering it.
    The code I put in here is experimental and in Scala (sorry, but I thing it is also read-able for Java dudes) and handles only a few SVG nodes. Batik is used to read it. It works (JavaFX 2.0 b42), but is definetly not very nice. Maybe that helps anyway :
    package org.rob.svgtransform
    import javafx.event.{Event, EventHandler}
    import org.w3c.dom.{NamedNodeMap, NodeList, Document}
    import javafx.scene.paint._
    import javafx.scene.text.Text
    import javafx.scene.image.{ImageView, Image}
    import javafx.scene.shape._
    import java.awt.image.RenderedImage
    import org.apache.batik.ext.awt.image.codec.png.PNGDecodeParam
    import org.apache.batik.ext.awt.image.codec.png.PNGImageDecoder
    import javax.imageio.ImageIO
    import org.apache.batik.ext.awt.image.codec.png.PNGImageEncoder
    import org.apache.batik.ext.awt.image.codec.png.PNGEncodeParam
    import collection.mutable.ListBuffer
    import javafx.application.Application
    import javafx.stage.Stage
    import javafx.scene.{Scene, Node, Group}
    import org.apache.batik.util.{XMLResourceDescriptor, ParsedURL}
    import org.apache.batik.dom.svg._
    import java.io._
    trait FxEventHandler extends EventHandler[Event] {
      def setSvgToFx(sf : ISVGToFX)
    trait ISVGToFX {
      def getRootNode : Group
      def getFxElementBySvgId(svgId : String) : Option[Node]
      def getSvgIdByFxElement(fxElement : Any) : Option[String]
      def getImageStrByImageId(imageId : String) : Option[String]
      def getSvgElementBySvgId(svgId : String) : Option[SVGOMElement]
    class SVGToFX(svgDocument : Document) extends ISVGToFX {
      var eventHandler : FxEventHandler = null
      var fxElementToSvgIdMap = Map.empty[Any, String]
      var svgIdToFxElementMap = Map.empty[String, Any]
      var imageIdToImageStrMap = Map.empty[String, String]
      var svgIdToSvgElementMap = Map.empty[String, SVGOMElement]
      var eventHandlerNodes = Set.empty[Node]
      val rootElement = toFx(null, svgDocument)
      def setEventHandler(eventHandler : FxEventHandler) {
        this.eventHandler = eventHandler
        for(eventHandlerNode <- eventHandlerNodes)
          eventHandlerNode.setOnMouseClicked(eventHandler)
        eventHandler.setSvgToFx(this)
      def getSvgIdByFxElement(fxElement : Any) : Option[String] = fxElementToSvgIdMap.get(fxElement)
      def getFxElementBySvgId(svgId : String) : Option[Node] = svgIdToFxElementMap.get(svgId) match {
        case Some(el) => {
          if(el.isInstanceOf[Node])
            Option(el.asInstanceOf[Node])
          else
            None
        case None => None
      def getImageStrByImageId(imageId : String) : Option[String] = imageIdToImageStrMap.get(imageId)
      def getSvgElementBySvgId(svgId : String) : Option[SVGOMElement] = svgIdToSvgElementMap.get(svgId)
      def getRootNode : Group = rootElement.asInstanceOf[Group]
      protected def traverse(nl: NodeList, level: Int): Unit = {
        for (i <- 0 until nl.getLength)
          val n = nl.item(i)
          if(n.isInstanceOf[SVGOMElement]){
            val svgElem = n.asInstanceOf[SVGOMElement]
            val id = svgElem.getId
            val attr : NamedNodeMap = svgElem.getAttributes
            val range = 0.until(attr.getLength)
            val sp = space(level)
            println(sp + "-----------------------------")
            println(sp + "class = " + svgElem.getClass.getName)
            for(k <- range){
              val node = attr.item(k)
              println(sp + "name = " + node.getNodeName + "; value = " + node.getNodeValue)
            println(sp + "BPMNDItoSVG: ID = " + id)
            println(sp + "-----------------------------")
          traverse(n.getChildNodes, level + 1)
      protected def space(level : Int) : String = {
        var sb = new StringBuffer("")
        for(x <- 0 to level)
          sb = sb.append("   ")
        sb.toString
      var noIdCounter : Int = 0
      protected def toFx(parentId : String, obj : Any): Any = {
        def doGroup(svgId: String, nl: NodeList, g : Group){
          for (i <- 0 until nl.getLength){
            val el = toFx(svgId, nl.item(i))
            if(el != null){
              el match {
                //            case i : ImageView => refToImageMap = refToImageMap + (svgId -> i)
                case n : Node => {
                  if(svgId != null && !"".equals(svgId ) && !fxElementToSvgIdMap.contains(n))
                    fxElementToSvgIdMap = fxElementToSvgIdMap + (n -> svgId)
                  g.getChildren.add(n)
        def getId(id : String) : String = {
          id match {
            case id : String => id
            case _ => {
              noIdCounter = noIdCounter + 1
              "noid_" + noIdCounter
        def getAttribute(attrs : NamedNodeMap, attr : String) : String = {
          val range = 0.until(attrs.getLength)
          for(k <- range){
            val node = attrs.item(k)
            if(attr.equals(node.getNodeName))
              return node.getNodeValue
            //println("name = " + node.getNodeName + "; value = " + node.getNodeValue)
          null
        var returnValue : Any = null
        val svgId : String = obj match {
          case e : SVGOMElement => {
            val svgEl = obj.asInstanceOf[SVGOMElement]
            getId(svgEl.getId)
          case _ => null
        obj match {
          case e : Document => {
            returnValue = new Group
            doGroup(svgId, e.getChildNodes, returnValue.asInstanceOf[Group])
            svgIdToFxElementMap = svgIdToFxElementMap + ("root" -> returnValue)
          case e : SVGOMDefsElement => {
            val nl = e.getChildNodes
            for (i <- 0 until nl.getLength)
              toFx(svgId, nl.item(i))  // ending up in fxElementMap because they only will be referenced and are not used directly
          case e : SVGOMLinearGradientElement => {
            val stopList = new java.util.ArrayList[Stop]()
            val nl = e.getChildNodes
            for (i <- 0 until nl.getLength){
              val el = toFx(svgId, nl.item(i))
              el match {
                case st : Stop => stopList.add(st)
                case _ =>
            val attr = e.getAttributes
            val startXStr = getAttribute(attr, "x1")
            val startYStr = getAttribute(attr, "y1")
            val stopXStr = getAttribute(attr, "x2")
            val stopYStr = getAttribute(attr, "y2")
            val startX = strToValue(startXStr).asInstanceOf[Double]
            val startY = strToValue(startYStr).asInstanceOf[Double]
            val stopX = strToValue(stopXStr).asInstanceOf[Double]
            val stopY = strToValue(stopYStr).asInstanceOf[Double]
            returnValue = new LinearGradient(startX,startY,stopX,stopY,false,CycleMethod.NO_CYCLE, stopList.asInstanceOf[java.util.List[Stop]])
            returnValue = new LinearGradient(0,0,0,1,true,CycleMethod.NO_CYCLE, stopList.asInstanceOf[java.util.List[Stop]])
          case e : SVGOMStopElement => {
            val attr = e.getAttributes
            val colorStr = getAttribute(attr, "style")
            val offsetStr = getAttribute(attr, "offset")
            val color = strToValue(colorStr).asInstanceOf[String]
            var offset = strToValue(offsetStr).asInstanceOf[Double]
            if(offset > 1.0)
              offset = 1.0
            returnValue = new Stop(offset, Color.web(color))
          case e : SVGOMImageElement => {
            val attr = e.getAttributes
            val imageDataStr = getAttribute(attr, "xlink:href")
            val widthStr = getAttribute(attr, "width")
            val heightStr = getAttribute(attr, "height")
            if(parentId != null)
              imageIdToImageStrMap = imageIdToImageStrMap + (parentId -> imageDataStr)
          case e : SVGOMEllipseElement => {
            val attr = e.getAttributes
            val transformStr = getAttribute(attr, "transform")
            val fillStr = getAttribute(attr, "fill")
            val rxStr = getAttribute(attr, "rx")
            val cxStr = getAttribute(attr, "cx")
            val ryStr = getAttribute(attr, "ry")
            val cyStr = getAttribute(attr, "cy")
            val strokeStr = getAttribute(attr, "stroke")
            val strokeWidthStr = getAttribute(attr, "stroke-width")
            val rx = strToValue(rxStr).asInstanceOf[Double]
            val cx = strToValue(cxStr).asInstanceOf[Double]
            val ry = strToValue(ryStr).asInstanceOf[Double]
            val cy = strToValue(cyStr).asInstanceOf[Double]
            val ellipse = new Ellipse(cx, cy, rx, ry)
            getFill(fillStr) match {
              case p : Paint => ellipse.setFill(p)
              case _ =>
            setTransforms(ellipse, transformStr)
            if(eventHandler != null)
              ellipse.setOnMouseClicked(eventHandler)
            returnValue = ellipse
          case e : SVGOMTextElement => {
            val attr = e.getAttributes
            val xStr = getAttribute(attr, "x")
            val fontSizeStr = getAttribute(attr, "font-size")
            val yStr = getAttribute(attr, "y")
            val fillStr = getAttribute(attr, "fill")
            val textAnchorStr = getAttribute(attr, "text-anchor")
            val fontDecorationStr = getAttribute(attr, "font-decoration")
            val fontFamilyStr = getAttribute(attr, "font-family")
            val fontWeightStr = getAttribute(attr, "font-weight")
            val x = strToValue(xStr).asInstanceOf[Double]
            val y = strToValue(yStr).asInstanceOf[Double]
            val t = new Text(x, y, e.getTextContent)
            //        val t = new Text(x - 30, y, e.getTextContent)
            //        t.setTextAlignment(TextAlignment.LEFT)
            eventHandlerNodes = eventHandlerNodes + t
            returnValue = t
          case e : SVGOMRectElement => {
            val attr = e.getAttributes
            val xStr = getAttribute(attr, "x")
            val yStr = getAttribute(attr, "y")
            val transformStr = getAttribute(attr, "transform")
            val fillStr = getAttribute(attr, "fill")
            val widthStr = getAttribute(attr, "width")
            val rxStr = getAttribute(attr, "rx")
            val ryStr = getAttribute(attr, "ry")
            val heightStr = getAttribute(attr, "height")
            val strokeStr = getAttribute(attr, "stroke")
            val strokeWidthStr = getAttribute(attr, "stroke-width")
            val x = strToValue(xStr).asInstanceOf[Double]
            val y = strToValue(yStr).asInstanceOf[Double]
            val rx = strToValue(rxStr).asInstanceOf[Double]
            val ry = strToValue(ryStr).asInstanceOf[Double]
            val strokeWidth = strToValue(strokeWidthStr).asInstanceOf[Double]
            val width = strToValue(widthStr).asInstanceOf[Double]
            val height = strToValue(heightStr).asInstanceOf[Double]
            val rect = new Rectangle(x, y, width, height)
            rect.setArcHeight(ry)
            rect.setArcWidth(rx)
            rect.setStroke(Color.GRAY)
            rect.setStrokeWidth(strokeWidth)
            getFill(fillStr) match {
              case p : Paint => rect.setFill(p)
              case _ =>
            setTransforms(rect, transformStr)
            eventHandlerNodes = eventHandlerNodes + rect
            returnValue = rect
          case e : SVGOMUseElement => {
            val attr = e.getAttributes
            val xStr = getAttribute(attr, "x")
            val yStr = getAttribute(attr, "y")
            val widthStr = getAttribute(attr, "width")
            val heightStr = getAttribute(attr, "height")
            val xlinkHrefStr = getAttribute(attr, "xlink:href")
            val x = strToValue(xStr).asInstanceOf[Double]
            val y = strToValue(yStr).asInstanceOf[Double]
            val width = strToValue(widthStr).asInstanceOf[Double]
            val height = strToValue(heightStr).asInstanceOf[Double]
            val xlinkHref = strToValue(xlinkHrefStr).asInstanceOf[String]
            returnValue = imageIdToImageStrMap.get(xlinkHref) match {
              case Some(imageDataStr) => {
                val i : Image = strToValue(imageDataStr).asInstanceOf[Image]
                val iv2 = new ImageView
                iv2.setImage(i)
                //            iv2.setFitWidth(100);
                //            iv2.setPreserveRatio(true)
                //            iv2.setSmooth(true)
                //            iv2.setCache(true)
                iv2.setX(x)
                iv2.setY(y)
                iv2.setFitHeight(height)
                iv2.setFitWidth(width)
                iv2
              case None => null
          case e : SVGOMPathElement => {
            val attr = e.getAttributes
            val fillStr = getAttribute(attr, "fill")
            val strokeWidthStr = getAttribute(attr, "stroke-width")
            val pathStr = getAttribute(attr, "d")
            val transformStr = getAttribute(attr, "transform")
            val strokeStr = getAttribute(attr, "stroke")
            val strokeWidth = strToValue(strokeWidthStr).asInstanceOf[Double]
            val svgPath = new SVGPath
            getFill(fillStr) match {
              case p : Paint => svgPath.setFill(p)
              case _ =>
            svgPath.setStrokeWidth(strokeWidth)
            svgPath.setContent(pathStr)
            svgPath.setStroke(Color.BLACK)
            setTransforms(svgPath, transformStr)
            eventHandlerNodes = eventHandlerNodes + svgPath
            returnValue = svgPath
          case e : SVGOMPolylineElement => {
            val attr = e.getAttributes
            val fillStr = getAttribute(attr, "fill")
            val strokeWidthStr = getAttribute(attr, "stroke-width")
            val pointsStr = getAttribute(attr, "points")
            val strokeStr = getAttribute(attr, "stroke")
            val transformStr = getAttribute(attr, "transform")
            val points = strToValue("points:" + pointsStr).asInstanceOf[Array[Double]]
            //        val points = Array[Double](676.0,672.0,676.0,630.0)
            val strokeWidth = strToValue(strokeWidthStr).asInstanceOf[Double]
            val polyline = new Polyline(points)
            getFill(fillStr) match {
              case p : Paint => polyline.setFill(p)
              case _ =>
            polyline.setStrokeWidth(strokeWidth)
            polyline.setStroke(Color.BLACK)
            setTransforms(polyline, transformStr)
            eventHandlerNodes = eventHandlerNodes + polyline
            returnValue = polyline
          case e : SVGOMCircleElement => {
            val attr = e.getAttributes
            val fillStr = getAttribute(attr, "fill")
            val strokeWidthStr = getAttribute(attr, "stroke-width")
            val strokeStr = getAttribute(attr, "stroke")
            val rStr = getAttribute(attr, "r")
            val cxStr = getAttribute(attr, "cx")
            val cyStr = getAttribute(attr, "cy")
            val transformStr = getAttribute(attr, "transform")
            val circle = new Circle
            getFill(fillStr) match {
              case p : Paint => circle.setFill(p)
              case _ =>
            val strokeWidth = strToValue(strokeWidthStr).asInstanceOf[Double]
            val r = strToValue(rStr).asInstanceOf[Double]
            val cx = strToValue(cxStr).asInstanceOf[Double]
            val cy = strToValue(cyStr).asInstanceOf[Double]
            circle.setStrokeWidth(strokeWidth)
            circle.setCenterX(cx);
            circle.setCenterY(cy);
            circle.setRadius(r);
            circle.setStroke(Color.BLACK)
            setTransforms(circle, transformStr)
            eventHandlerNodes = eventHandlerNodes + circle
            returnValue = circle
          case e : SVGOMSVGElement => {
            val attr = e.getAttributes
            val transformStr = getAttribute(attr, "transform")
            val g = new Group
            doGroup(svgId, e.getChildNodes, g)
            setTransforms(g, transformStr)
            returnValue = g
          case e : SVGOMGElement => {
            val attr = e.getAttributes
            val transformStr = getAttribute(attr, "transform")
            val g = new Group
            doGroup(svgId, e.getChildNodes, g)
            setTransforms(g, transformStr)
            returnValue = g
          case e => { println("Element " + e + " is not supported yet!")
        if(returnValue != null && svgId != null && !svgId.equals("")){
          fxElementToSvgIdMap = fxElementToSvgIdMap + (returnValue -> svgId)
          svgIdToFxElementMap = svgIdToFxElementMap + (svgId -> returnValue)
          if(obj != null && obj.isInstanceOf[SVGOMElement])
            svgIdToSvgElementMap = svgIdToSvgElementMap + (svgId -> obj.asInstanceOf[SVGOMElement])
        returnValue
      def setTransforms(node : Node, transformStr : String) {
        var translate : Array[Double] = null
        var rotate : Array[Double] = null
        if(transformStr != null){
          val translateIdx = transformStr.indexOf("translate(")
          val rotateIdx = transformStr.indexOf("rotate(")
          if(translateIdx >= 0){
            val translateEndIdx = transformStr.indexOf(")", translateIdx)
            val translateStr = transformStr.substring(translateIdx + 10, translateEndIdx)
            translate = listToDoubleArray(translateStr)
          if(rotateIdx >= 0){
            val rotateEndIdx = transformStr.indexOf(")", rotateIdx)
            val rotateStr = transformStr.substring(rotateIdx + 7, rotateEndIdx)
            rotate = listToDoubleArray(rotateStr)
        if(translate != null){
          node.setTranslateX(translate(0))
          node.setTranslateY(translate(1))
        if(rotate != null){
          node.setRotate(rotate(0))
          //      node.setRotationAxis(new Point3D(rotate(1), rotate(2), 0.0))
      def getFill(str : String) : Paint = {
        if(str != null){
          str.startsWith("url(#") match {
            case true => {
              val fillLink = strToValue(str).asInstanceOf[String]
              val fill = svgIdToFxElementMap.get(fillLink) match {
                case Some(element) => element match {
                  case lg : LinearGradient => lg
                  case _ => Color.GREEN
                case None => Color.BLUE
              fill
            case false => str.startsWith("none") match {
              case false => Color.web(str, 1.0)
              case true =>  Color.WHITE  // ToDo: make sure this is the background color
        } else
          Color.RED
      def strToValue(str : String) : Any = {
        var returnValue : Any = null
        if(str != null){
          if(str.endsWith("%")){
            val s = str.substring(0, str.length() - 1)
            returnValue = s.toDouble
          } else if(str.startsWith("data:image")){
            val pu = new ParsedURL(str)
            val pust = pu.openStream()
            var awti : RenderedImage = null
            if(str.contains("png")){
              val pngdp = new PNGDecodeParam
              val pngde = new PNGImageDecoder(pust, pngdp)
              awti = pngde.decodeAsRenderedImage()
            } else if(str.contains("gif")){
              val is = new BufferedInputStream(pust);
              awti = ImageIO.read(is);
            if(awti != null){
              val baos = new ByteArrayOutputStream
              val pngen = new PNGImageEncoder(baos, new PNGEncodeParam.Palette)
              pngen.encode(awti)
              val bais = new ByteArrayInputStream(baos.toByteArray)
              returnValue = new Image(bais)
            } else
              returnValue = null
          } else if(str.startsWith("points:")){
            returnValue = listToDoubleArray(str.substring(7))
          } else if(str.startsWith("#")){
            returnValue = str.substring(1)
          } else if(str.startsWith("url(#")){
            val endIdx = str.indexOf(")")
            returnValue = str.substring(5,endIdx)
          } else if(str.startsWith("stop-color:")){
            returnValue = str.substring(11)
          } else {
            returnValue = str.toDouble
        returnValue
      def listToDoubleArray(listStr : String) : Array[Double] = {
        val seperators = Array[Char](' ', ',', ')')
        val ps = listStr.split(seperators)
        val lb = new ListBuffer[Double]()
        for(v <- ps)
          lb +=  strToValue(v).asInstanceOf[Double]
        lb.toArray
    trait SVGElement{
      val svgId : String
    object SVGToFXTest {
      def main(args : Array[String]){
        Application.launch(classOf[SVGToFXTest], args)
    class SVGToFXTest extends Application {
      def start(st : Stage) {
        st.setWidth(1000)
        st.setHeight(800)
        st.setTitle("SVGToFX");
        st.setResizable(true);
        val root = new Group
        val scene = new Scene(root)
        st.setScene(scene)
        val fr = new FileReader("D:\\Development\\Playground\\SvgTransform\\data\\Test2.svg")
        val parser: String = XMLResourceDescriptor.getXMLParserClassName
        val fa: SAXSVGDocumentFactory = new SAXSVGDocumentFactory(parser)
        val doc = fa.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, fr).asInstanceOf[SVGOMDocument]
        val svgToFx = new SVGToFX(doc)
        root.getChildren.add(svgToFx.getRootNode)
        println("Test")
        st.setVisible(true)
    }Edited by: user6782617 on 07.10.2011 04:56

  • FFT help

      Hello all,
    I have a code that is tracing data from a Optical Spectrum Analyzer when certain conditions are met. (fft.VI) The data collected is a reflectance spectrum of a sensor.State 3 is the state that is collecting the data.
     I want to make some data processing on the collected data. I attached a sample data set that is obtained by the code. 
     What I want is converting the power array from dbm scale to mW scale (I have done that), filtering the data with a bandpass filter (the expected frequency of the array starts from 100e-6 and goes up to 200e-6), normalizing data and finding the frequency of the spectrum. I found the necessary VIs and wired everthing but it gave some meaningless results.
    Why do you think is wrong in the code? (the expected frequency should be around 130e-6 but according to the code it is 9.645)
     Thank you
    Attachments:
    code_saturday.zip ‏195 KB
    data set.xls ‏162 KB

    Looks like you just started out, because there are some very strange constructs that either make little sense or are done way too complicated.
    ( e.g. FFT.vi: State 1: The while loop consumes all CPU doing practically nothing. It needs a small wait. ["collect data?"_AND_ "true"] is the same as ["collect data?"]. You can delete the "boolean AND" and the TRUE diagram constant, they make no difference. State 3: don't operate on entire paths as strings, because you will break platform independence. Use path constants and "build path" and operate only on filenames as strings. You should create some data dependency to ensure that resetting the history data occurs before the loops start. Why is the number of elements a hidden control that is zero instead of 30? Use a diagram constant! The subVI "get last 30 elements could be done with a simple "rotate array" and "replace array element", all that code is way too complicated. etc. etc....)
    First of all, whe you attach multiple VIs, please tell us what the name of the toplevel VI is to make our life easier. It's not obvious at first.
    Back to your original question. You are feeding a plain 1D array to the FFT, so there is no dt information, this also means that the df of the transform will need to be calculated based on the correct dt that you need to obtain from elsewhere. Once you have df, you can set the x-axis of the transform accordingly (xo, dx). (more information)
    LabVIEW Champion . Do more with less code and in less time .

  • Acrobat in Flash

    Hi !
    I found quite a few topics about putting flash into pdf, but
    my problem is that I want to embed PDF content inside a flash
    application. My desires would be to embed 3D acrobat data, even
    without acrobat frame/viewer into a flash app. I don't even dream
    about such a thing possible in flash, but if there's everything
    half as great, I would really appreciate if somebody would let me
    know.
    Thank you,
    Sub

    Displaying a 3D viewport via Flash Player is not going to happen yet. Although FP10 is promoted as having "3D features" it's strictly a 2.5D kernel - there's no internal concept of Z-space, just perspective and rotation arrays to make it look like there is. Dropping a U3D or OBJ into a Flash timeline would be nice, but you'll have to wait.
    Meanwhile, Acrobat 9 can do it perfectly happily, and R9 penetration is quite good - not as deep as FP, but it's a different demographic. People who use the Web for CAD-type business will almost certainly have it, but a kid surfing for games may not. It's also extremely simple to handle legacy visitors to a page with embedded 3D PDF content; we've been doing it since 8.5 launched and our server logs currently run at around 65% having R9 on arrival, and 15% installing it and coming back.
    There are other 3D browser plugins and OS applets such as Right Hemisphere's Deep View, but in general visitors get the point of installing R9 as they've heard of Adobe. Pushing them to another install, however good and safe it may be, is far harder if they don't recognize the name. You also have the advantage that it's a lot more work to drag your original model out from a PDF, whereas some of the third-party viewers simply push the raw mesh file to the visitor.

  • PN sequence Generation

    How to generate a PN sequence in LABVIEW. PN pseudorandom sequence generates a sequence of pseudorandom
    binary numbers. A pseudonoise sequence can be used in a pseudorandom
    scrambler and descrambler. It can also be used in 
    spread-spectrum system.

    PRNGs (aka PRBS) are usually based on Linear Feedback Shift Registers (LFSRs) so a search on LFSRs is a good idea to see the theory behind them.
    One difference with LFSRs and the LabVIEW "dice" (which does output pseudorandom numbers) is that LFSRs can't output an all zero state. A seed value is used to start the sequence (and this can't be all zeros either).
    Here is an 8 bit LSFR:
    Note that the rotate array function is only there for aesthetic purposes.
    The same output will always be returned for a given seed value and iteration count of the For loop.
    steve
    Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
    question. Give "Kudos" to replies that help.

  • Convert the output sequence of complex FFT

    I am using complex FFT to do IQ demodulation.
    the input X of complex FFT  is  cos(x)+i*sin(x). abs(FFT(X)) is the frequency response of input X. I need to convert the output sequence the format
    FROM: DC f....Nyquist Frequency...–f
    TO: -Fre_nyquist ...DC... Fre_nyquist
    Is there any function I can use to do this convertion? thanks

    Just use "rotate array" from the array palette (LabVIEW 7.1 or lower) and rotate by n/2.
    If you have LabVIEW 8.0, simply wire a TRUE to the "shift?" input for a DC centered spectrum.
    LabVIEW Champion . Do more with less code and in less time .

  • Is there a way to rotate an array on the front panel?

    Is there a way to rotate an array on the front panel?  For example, I want element [0] to be at the bottom of an array that's expanded to show the elements vertically.
    Thanks in advance.

    I do not think that there is any way to make an array control or indicator display that way.
    You might be able to reverse the array, creating an upside down display. If you also need the user to index it, then it gets trickier.  Hide the array index display.  Create another numeric control to look like the index control.  When the value of the new control is changed, subtract the value from the last index of the array and use the difference to index the array.  You may need to adjust by +/-1, so try it to be sure.
    Lynn

  • Rotation animation using an array

    Hi, I'm fairly new to using java and I've been trying to figure out a couple of things but I just can't find what im looking for by searching. The IDE i'm using is BlueJ and any help would be appreciated.
    1. Take an array of N images (no X or Y movement) and get it to track the mouse so that as the mouse moves in a circle around the image the imageIndex changes so that the current image is facing the mouse
    2. Setting up keybindings so that an array of images will "rotate" the same way as in number 1

    Add a MouseMotionListener.
    Determine the position of the cursor relative to your image.
    Determine the image that's to be shown.
    Draw it.

  • I Need an Array of Rotated String Indicators

    Greetings,
    I need to make an array containing verticle strings. The size of the array will very during runtime.
    I know that for a single string indicator I can ignore the actual control, rotate the caption and change its text property and for a cluster there's an array of references to each member which can be used for accessing the caption text of each member but it appears that all members of an array share a caption.
    Am I correct that there's no way (yet) to do that?
    Peace
    phroggie

    Hello Phrog,
    It seems like the solution proposed by Paul is sufficient for your application. But I would like to suggest an alternative solution  (with its own trade offs) that may address some of your functionality concerns. The width of a string indicator and text wrapping can both be set in the properties menu. Because of these settings, each character would appear vertically stacked. An array of these string indicators could be sized dynamically and viewed using a scroll bar. Unfortunately the letter “m” is wider than combinations of other two letters such as “is”. If the width is set too low then the letter “m” gets cutoff. If the width is set too high then smaller letters like “is” appear on the same line. There is no magic width that prevents these two cases.
    The example I have attached works around the letter “m” by appending a space between each non-m character and uses an indicator width of 23 pixels. This is enough space to display the letter “m” while the inserted spaces prevent smaller letters from appearing on the same line. Despite this inconvenience, you gain the use of built in dynamic array sizing and the horizontal  scroll bar.
    Otherwise, scroll bar functionality is not built into clusters. It is possible to implement a scroll bar for a cluster programmatically as shown in this community example: https://decibel.ni.com/content/docs/DOC-35704
    This solution isn't necessarily easy to implement, so using stacked characters in an array may be a worthwhile trade off depending on your application.
    Earl C
    Applications Engineer
    National Instruments
    Attachments:
    Vertical Strings.vi ‏14 KB

  • Get rectangular array after Image rotated

    I want to extract underlying data from a rectangle drawn on an image after it has been rotated.
    The rectangle has been drawn with a mouse, and the mouse points are inverse-transformed
    into original data coordinates.
    The problem is the same as extracting data from a rectangular array that is not oriented on either
    side along the coordinates (indices) of the original data.
    I could apply an affine transform to the entire image and get the data that way, but the images
    are quite large and I prefer to extract only the data I need.
    Has anybody done this?

    I'm unclear what you're trying to do, but whenever I need precise rotations translated fast, I used the affineTransform.transform(float[] src,int offset,float[] dst,int offset2) method.
    And if you need the inverse transformation, just say:
    AffineTransform inverted = originalTransform.createInverse();
    That will get you just the points, without messing with shapes or PathIterators or anything else.

  • Pointer Manipulation: Wrap Around/Rollover/Rotation of LabVIEW Arrays and Waveforms???

    I know we can't use pointers in LabVIEW, but I was wondering if there's any way we can do wrap-around [or "rollover," or "rotation"] of Array [or Waveform] values without having to make copies of the Array [or Waveform]?
    For instance, suppose I'm reading one second's worth of data into a five second buffer. After the first five seconds, I've got
    1st (1/5)th: 1st second's worth of data
    2nd (1/5)th: 2nd second's worth of data
    3rd (1/5)th: 3rd second's worth of data
    4th (1/5)th: 4th second's worth of data
    5th (1/5)th: 5th second's worth of data
    Now I read the sixth second's worth of data, and overwrite the [original] first second, so that I have
    1st (1/5)th: 6th second's worth of data
    2nd (1/5)th: 2nd second's worth of data
    3rd (1/5)th: 3rd second's worth of data
    4th (1/5)th: 4th second's worth of data
    5th (1/5)th: 5th second's worth of data
    and in C, or C++, I'd just move the pointer up to the second (1/5)th of data, and start from there.
    The LabVIEW Complex FFT is another place where this would be really useful. The Help File for the Complex FFT is in
    Help | VI and Function Reference | Analyze VIs | Signal Processing VIs | Frequency Domain VIs | Complex FFT.
    If you read the Help File, you see that LabVIEW returns an FFT with values in the range
    [0, 2n - 1)
    rather than the standard
    [-n, n - 1)
    i.e. LabVIEW takes the negative frequencies and tacks them on at the end, after the positive frequencies.
    I'd like to be able to view my FFTs with the negative frequencies where they're supposed to be [i.e to the left of zero], and this would be SO easy if I could just move the underlying data pointer of the Waveform forward to the halfway point.
    But, of course, in LabVIEW, I don't have pointers, so I was wondering: Are there any built-in VIs for Array [or Waveform] manipulation that will perform this sort of wrap-around [or "rollover," or "rotation"] of the data? If so, I couldn't find them. Ideally, such a VI would have two inputs: {old Array, new starting point}, and one output: {new Array}. Similarly with Waveforms, only you'd need to manipulate t0 as well.
    Or do I have to copy the entire data set to a new Array [or Waveform] each time I reach the end of the buffer?
    Thanks!

    > Ideally, such a VI would have two inputs: {old Array, new starting point}, and one output: {new Array}.
    Have a look at "rotate 1D array" in the array palette (second row, fourth column).
    (Sorry, I dont use waveform data).
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for

  • Rules inside email templates

    Has anyone tried calling a rule from inside an email template? It seems like everything has to be passed in from the workflow to the template. I'm wondering if I can call a rule from inside the template itself to get the data. Thanks!!

  • Previewing photo prep on TV Monitor

    What is the best and yet most inexpensive device to use to connect a G5 to a TV for image prep and proofing purposes and do you consider this ability to be necessary, crucial or a luxury? G5   Mac OS X (10.4.3)  

  • Caching of static files

    Hello all, I was wondering if any of you has a solution to the following problem. If you use javascript and store these files as static files within Apex, the files will be downloaded on the client cache without an expire date. Now if I have an appli

  • IPhone: get the GSM signal in numbers WITHOUT jailbreaking? Is it possible?

    Hi guys, I need to measure the signal rate in different parts of a building. I know that it can be done with SBSettings, but I don't want to jailbreak my phone. Can this configuration (getting the signal strength in numbers instead of the lines) be d

  • TS3694 error 3194 how to solve, please help thank you.

    Error 3194 how to solve it thank you.