FrameTransform.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package org.ros.rosjava_geometry;
00018 
00019 import com.google.common.base.Preconditions;
00020 
00021 import org.ros.message.Time;
00022 
00029 public class FrameTransform {
00030 
00031   private final Transform transform;
00032   private final FrameName source;
00033   private final FrameName target;
00034   private final Time time;
00035 
00036   public static FrameTransform fromTransformStampedMessage(
00037       geometry_msgs.TransformStamped transformStamped) {
00038     Transform transform = Transform.fromTransformMessage(transformStamped.getTransform());
00039     String target = transformStamped.getHeader().getFrameId();
00040     String source = transformStamped.getChildFrameId();
00041     Time stamp = transformStamped.getHeader().getStamp();
00042     return new FrameTransform(transform, FrameName.of(source), FrameName.of(target), stamp);
00043   }
00044 
00059   public FrameTransform(Transform transform, FrameName source, FrameName target, Time time) {
00060     Preconditions.checkNotNull(transform);
00061     Preconditions.checkNotNull(source);
00062     Preconditions.checkNotNull(target);
00063     this.transform = transform;
00064     this.source = source;
00065     this.target = target;
00066     this.time = time;
00067   }
00068 
00069   public Transform getTransform() {
00070     return transform;
00071   }
00072 
00073   public FrameName getSourceFrame() {
00074     return source;
00075   }
00076 
00077   public FrameName getTargetFrame() {
00078     return target;
00079   }
00080 
00081   public FrameTransform invert() {
00082     return new FrameTransform(transform.invert(), target, source, time);
00083   }
00084 
00089   public Time getTime() {
00090     return time;
00091   }
00092 
00093   public geometry_msgs.TransformStamped toTransformStampedMessage(
00094       geometry_msgs.TransformStamped result) {
00095     Preconditions.checkNotNull(time);
00096     result.getHeader().setFrameId(target.toString());
00097     result.getHeader().setStamp(time);
00098     result.setChildFrameId(source.toString());
00099     transform.toTransformMessage(result.getTransform());
00100     return result;
00101   }
00102 
00103   @Override
00104   public String toString() {
00105     return String.format("FrameTransform<Source: %s, Target: %s, %s, Time: %s>", source, target,
00106         transform, time);
00107   }
00108 
00109   @Override
00110   public int hashCode() {
00111     final int prime = 31;
00112     int result = 1;
00113     result = prime * result + ((source == null) ? 0 : source.hashCode());
00114     result = prime * result + ((target == null) ? 0 : target.hashCode());
00115     result = prime * result + ((time == null) ? 0 : time.hashCode());
00116     result = prime * result + ((transform == null) ? 0 : transform.hashCode());
00117     return result;
00118   }
00119 
00120   @Override
00121   public boolean equals(Object obj) {
00122     if (this == obj)
00123       return true;
00124     if (obj == null)
00125       return false;
00126     if (getClass() != obj.getClass())
00127       return false;
00128     FrameTransform other = (FrameTransform) obj;
00129     if (source == null) {
00130       if (other.source != null)
00131         return false;
00132     } else if (!source.equals(other.source))
00133       return false;
00134     if (target == null) {
00135       if (other.target != null)
00136         return false;
00137     } else if (!target.equals(other.target))
00138       return false;
00139     if (time == null) {
00140       if (other.time != null)
00141         return false;
00142     } else if (!time.equals(other.time))
00143       return false;
00144     if (transform == null) {
00145       if (other.transform != null)
00146         return false;
00147     } else if (!transform.equals(other.transform))
00148       return false;
00149     return true;
00150   }
00151 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49