private void LoadJsonData(TextReader jsonReader)
        {
            try
            {
                JObject jsonData = JObject.Load(new JsonTextReader(jsonReader));

                JToken collections = jsonData["l"] ?? jsonData["collections"];

                JToken collection = collections.Values().First();

                int numCoordSystems = collection["_num_coord_systems"].Value<int>();

                CoordinateSystems = new CoordinateSystem[numCoordSystems];

                JToken coordSystems = collection["x"] ?? collection["coord_systems"];

                for (int id = 0; id < numCoordSystems; id++)
                {
                    CoordinateSystems[id] = new CoordinateSystem(id);

                    JToken coordSystem = coordSystems[Convert.ToString(id)];

                    JToken pointcloud = coordSystem["k"] ?? coordSystem["pointcloud"];

                    if (pointcloud != null)
                    {
                        string s = pointcloud[0].Value<string>();

                        if (!string.IsNullOrEmpty(s))
                        {
                            JToken binFileCount = pointcloud[1];

                            CoordinateSystems[id].PointCloud = new PointCloud(id, binFileCount.Value<int>());
                        }
                    }

                    JToken projectors = coordSystem["r"] ?? coordSystem["projectors"];

                    List<CameraParameters> cameraParameterList = new List<CameraParameters>();

                    foreach (JToken projector in projectors.Values())
                    {
                        string imageName = ((JProperty)projector.Parent).Name;

                        JToken projectorParameters = projector["j"] ?? projector["image_position_rotation_aspect_focallength"];

                        //int imageId = projectorParameters[0].Value<int>(); // this is out of all the PhotoSynth images, i.e. the thumbs or distort directory
                        int imageId = int.Parse(imageName); // this is out of the working coordinate system, i.e. /pmvs/visualize

                        //string sImageId = projectorParameters[0].Value<string>() + "_or_" + int.Parse(imageName);

                        CameraPosition position = new CameraPosition()
                        {
                            X = projectorParameters[1].Value<double>(),
                            Y = projectorParameters[2].Value<double>(),
                            Z = projectorParameters[3].Value<double>()
                        };

                        CameraRotation rotation = CameraRotation.FromNormalizedQuaternion(
                            projectorParameters[4].Value<double>(),
                            projectorParameters[5].Value<double>(),
                            projectorParameters[6].Value<double>());

                        double aspectRatio = projectorParameters[7].Value<double>();

                        double focalLength = projectorParameters[8].Value<double>();

                        JToken radialDistortion = projector["f"] ?? projector["radial_distortion"];

                        CameraDistortion distortion;

                        if (radialDistortion != null)
                            distortion = new CameraDistortion()
                            {
                                K1 = radialDistortion[0].Value<double>(),
                                K2 = radialDistortion[1].Value<double>()
                            };
                        else
                            distortion = new CameraDistortion();

                        cameraParameterList.Add(new CameraParameters(imageId, position, rotation, aspectRatio, focalLength, distortion));
                    }

                    cameraParameterList.Sort(new Comparison<CameraParameters>((cp1, cp2) => cp1.ImageId.CompareTo(cp2.ImageId)));

                    CoordinateSystems[id].CameraParameterList = new CameraParameterList(cameraParameterList);
                }
            }
            catch (Exception e)
            {
                if (e is JsonReaderException)
                    throw new SynthDataLoadException("An error occurred while processing synth data.", e);

                throw;
            }
        }
 public CameraParameters(int imageId, CameraPosition position, CameraRotation rotation, double aspectRatio, double focalLength, CameraDistortion radialDistortion)
 {
     ImageId = imageId;
     Position = position;
     Rotation = rotation;
     AspectRatio = aspectRatio;
     FocalLength = focalLength;
     RadialDistortion = radialDistortion;
 }