Ejemplo n.º 1
0
 public Lens(int id, Vector3Pair position, Transform3 transform, List <OpticalSurface> surfaces,
             List <Element> elementList, Stop stop)
     : base(id, position, transform, elementList)
 {
     this._stop     = stop;
     this._surfaces = surfaces;
 }
Ejemplo n.º 2
0
        protected Medium _mat = Air.air; // FIXME - should be settable

        public RaySource(int id, Vector3Pair p, Transform3 transform, double min_intensity, double max_intensity,
                         List <SpectralLine> spectrum) : base(id, p, transform)
        {
            _max_intensity = max_intensity;
            _max_intensity = min_intensity;
            _spectrum      = spectrum;
        }
Ejemplo n.º 3
0
        public void set_camera_direction(Vector3 dir)
        {
            Transform3 t = get_camera_transform();

            t = t.set_direction(dir);
            set_camera_transform(t);
        }
Ejemplo n.º 4
0
        public void set_camera_position(Vector3 pos)
        {
            Transform3 t = get_camera_transform();

            t = t.set_translation(pos);
            set_camera_transform(t);
        }
Ejemplo n.º 5
0
        List <TracedRay> process_rays(Surface surface, TraceIntensityMode m, RayTraceResults result,
                                      List <TracedRay> input)
        {
            RayTraceParameters params_ = result._parameters;
            List <TracedRay>   rays    = new();

            foreach (TracedRay i in input)
            {
                TracedRay ray = i;

                Transform3 t
                    = ray.get_creator().get_transform_to(surface);
                Vector3Pair local1 = t.transform_line(ray.get_ray());

                Vector3Pair pt = surface is Stop
                    ? intersect((Stop)surface, params_, local1)
                    : intersect(surface, params_, local1);

                if (pt != null)
                {
                    result.add_intercepted(surface, ray);
                    TracedRay cray = trace_ray(surface, m, result, ray, local1, pt);
                    if (cray != null)
                    {
                        rays.Add(cray);
                    }
                }
            }

            return(rays);
        }
Ejemplo n.º 6
0
        static bool draw_traced_ray_recurs(Renderer renderer, TracedRay ray, double lost_len,
                                           Element ref_, bool hit_image, int D, bool draw_lost)
        {
            Transform3 t1        = ray.get_creator().get_transform_to(ref_);
            Element    i_element = null;

            Vector3 v0 = t1.transform(ray.get_ray().origin());
            Vector3 v1;

            if (ray.is_lost())
            {
                if (!draw_lost)
                {
                    return(false);
                }
                v1 = t1.transform(ray.get_ray().origin().plus(ray.get_ray().direction().times(lost_len)));
            }
            else
            {
                i_element = ray.get_intercept_element();
                Transform3 t2 = i_element.get_transform_to(ref_);
                v1 = t2.transform(ray.get_intercept_point());
            }

            Vector3Pair p    = new Vector3Pair(v0, v1);
            bool        done = false;

            for (TracedRay child_ray = ray.get_first_child(); child_ray != null; child_ray = child_ray.get_next_child())
            {
                if (draw_traced_ray_recurs(renderer, child_ray, lost_len, ref_, hit_image, 2, false))
                {
                    done = true;
                }
            }

            if (!done && hit_image && !(i_element is Image))
            {
                return(false);
            }

            switch (D)
            {
            case 2:
                // skip non tangential rays in 2d mode
                if (Math.Abs(p.x1()) > 1e-6)
                {
                    return(false);
                }

                draw_ray_line(renderer, new Vector2Pair(p.v0.project_zy(), p.v1.project_zy()), ray);
                break;

            case 3:
                draw_ray_line(renderer, p, ray);
                break;
            }

            return(true);
        }
Ejemplo n.º 7
0
        /**
         * Composition. New translation is set to: apply parent's linear transformation on child translation and add parent translation.
         * New linear matrix -s the product of the parent and child matrices.
         * TODO check terminology is correct
         *
         * @param p Parent component
         * @param c Child component
         */
        public static Transform3 compose(Transform3 p, Transform3 c)
        {
            Vector3 translation         = p.apply_rotation(c.translation).plus(p.translation);
            bool    use_rotation_matrix = p.use_rotation_matrix || c.use_rotation_matrix;
            Matrix3 rotation_matrix     = p.rotation_matrix.times(c.rotation_matrix);

            return(new Transform3(translation, rotation_matrix, use_rotation_matrix));
        }
Ejemplo n.º 8
0
        /**
         * Rotate by x, y, and z axis.
         *
         * @param v Vector with angles per axis
         */
        public Transform3 rotate_axis_by_angles(Vector3 v)
        {
            Transform3 t = this;

            for (int i = 0; i < 3; i++)
            {
                // i stands for x,y,z axis
                if (v.v(i) != 0.0)
                {
                    t = t.rotate_axis_by_angle(i, v.v(i));
                }
            }

            return(t);
        }
Ejemplo n.º 9
0
        void draw_2d_e(Renderer r, Stop stop, Element ref_)
        {
            Vector3 mr  = new Vector3(0, stop.get_external_radius(), 0);
            Vector3 top = new Vector3(0, stop.get_shape().get_outter_radius(Vector2.vector2_01), 0);
            Vector3 bot = new Vector3(0, -stop.get_shape().get_outter_radius(Vector2.vector2_01.negate()),
                                      0);

            Transform3 t     = stop.get_transform_to(ref_);
            Rgb        color = r.get_style_color(stop.get_style());

            r.group_begin("");
            r.draw_segment(t.transform(top), t.transform(mr), color);
            r.draw_segment(t.transform(bot), t.transform(mr.negate()), color);
            r.group_end();
        }
Ejemplo n.º 10
0
            public virtual void compute_global_transforms(Transform3Cache tcache)
            {
                //System.err.println("Computing coordinate for " + this);

                Transform3 t = _transform; // local transform

                Element.Builder p = this._parent;
                while (p != null)
                {
                    t = Transform3.compose(p._transform, t);
                    p = p._parent;
                }

                tcache.put_local_2_global_transform(this._id, t);           // Local to global
                tcache.put_global_2_local_transform(this._id, t.inverse()); // Global to local
            }
Ejemplo n.º 11
0
        void get_2d_points(Surface surface, Vector2[] array, double start,
                           double end, Element ref_)
        {
            int count = array.Length;

            double y1   = start;
            double step = (end - start) / (count - 1);
            int    i;

            Transform3 t = surface.get_transform_to(ref_);

            for (i = 0; i < (int)count; i++)
            {
                Vector3 v = new Vector3(0.0, y1, 0.0);
                v = v.z(surface.get_curve().sagitta(v.project_xy()));

                array[i] = t.transform(v).project_zy();
                y1      += step;
            }
        }
Ejemplo n.º 12
0
        List <TracedRay> process_rays(Stop surface, TraceIntensityMode m, RayTraceResults result, List <TracedRay> input)
        {
            List <TracedRay> rays = new();

            foreach (TracedRay i in input)
            {
                TracedRay ray = i;

                Transform3  t     = ray.get_creator().get_transform_to(surface);
                Vector3Pair local = t.transform_line(ray.get_ray());

                Vector3 origin = surface.get_curve().intersect(local);
                if (origin != null)
                {
                    if (origin.project_xy().len() < surface.get_external_radius())
                    {
                        Vector3 normal = surface.get_curve().normal(origin);

                        if (local.direction().z() < 0)
                        {
                            normal = normal.negate();
                        }

                        result.add_intercepted(surface, ray);

                        TracedRay cray = trace_ray(surface, m, result, ray, local, new Vector3Pair(origin, normal));
                        if (cray != null)
                        {
                            rays.Add(cray);
                        }
                    }
                }
            }

            return(rays);
        }
Ejemplo n.º 13
0
 public Element.Builder transform(Transform3 transform3)
 {
     this._transform = transform3;
     return(this);
 }
Ejemplo n.º 14
0
 public Builder rotate(double x, double y, double z)
 {
     this._transform = this._transform.rotate_axis_by_angles(new Vector3(x, y, z));
     return(this);
 }
Ejemplo n.º 15
0
 public Builder localPosition(Vector3 v)
 {
     this._transform =
         new Transform3(v, this._transform.rotation_matrix, this._transform.use_rotation_matrix);
     return(this);
 }
Ejemplo n.º 16
0
 public virtual Builder position(Vector3Pair position)
 {
     this._position  = position;
     this._transform = new Transform3(position);
     return(this);
 }
Ejemplo n.º 17
0
 public Element(int id, Vector3Pair p, Transform3 transform)
 {
     this._id        = id;
     this._position  = p;
     this._transform = transform;
 }
Ejemplo n.º 18
0
 /** Get modifiable reference to 3d camera transform */
 public abstract void set_camera_transform(Transform3 t);
Ejemplo n.º 19
0
 public Surface(int id, Vector3Pair p, Transform3 transform, Curve curve, Shape shape) : base(id, p, transform)
 {
     this._curve = curve;
     this._shape = shape;
 }
Ejemplo n.º 20
0
 /** Get modifiable reference to 3d camera transform */
 public override void set_camera_transform(Transform3 t)
 {
     this._cam_transform = t;
 }
Ejemplo n.º 21
0
 public PointSource(int id, Vector3Pair p, Transform3 transform, double min_intensity, double max_intensity,
                    List <SpectralLine> spectrum, SourceInfinityMode mode) : base(id, p, transform, min_intensity, max_intensity,
                                                                                  spectrum)
 {
     _mode = mode;
 }
Ejemplo n.º 22
0
 public Group(int id, Vector3Pair p, Transform3 transform3, List <Element> elements) : base(id, p, transform3)
 {
     this._elements = elements;
 }