//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Text;
using System.IO;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.PointClouds;
namespace Revit.SDK.Samples.CS.PointCloudEngine
{
///
/// An implementation for a file-based point cloud.
///
///
/// The file format is based upon XML. A sample XML looks like:
///
///
///
/// |
///
///
///
///
/// |
///
///
///
///
///
/// |
///
///
/// The scale value applies to the entire point cloud. One or more cell values should be supplied,
/// with the coordinates of the opposing corners, a color, and an option whether or not to randomize
/// the generated points.
///
class FileBasedPointCloud : PointCloudAccessBase, IPointCloudAccess
{
#region Class Member Variables
String m_fileName;
#endregion
#region Class Methods
///
/// Constructs a new XML-based point cloud access.
///
/// The full path to the file.
public FileBasedPointCloud(String fileName)
{
m_fileName = fileName;
Setup();
}
///
/// Sets up the file-based point cloud.
///
private void Setup()
{
if (File.Exists(m_fileName))
{
StreamReader reader = new StreamReader(m_fileName);
XDocument xmlDoc = XDocument.Load(new XmlTextReader(reader));
reader.Close();
SetupFrom(xmlDoc.Element("PointCloud"));
}
}
#endregion
#region IPointCloudAccess Members
///
/// The implementation of IPointCloudAccess.GetName().
///
/// The name (the file name).
public String GetName()
{
return m_fileName;
}
///
/// The implementation of IPointCloudAccess.GetColorEncoding()
///
/// The color encoding.
public PointCloudColorEncoding GetColorEncoding()
{
return PointCloudColorEncoding.ABGR;
}
///
/// The implementation of IPointCloudAccess.CreatePointSetIterator().
///
/// The filter.
/// The view id (unused).
/// The new iterator.
public IPointSetIterator CreatePointSetIterator(PointCloudFilter rFilter, ElementId viewId)
{
return new PointCloudAccessBase.PointCloudAccessBaseIterator(this, rFilter);
}
///
/// The implementation of IPointCloudAccess.CreatePointSetIterator().
///
/// The filter.
/// The density.
/// The view id (unused).
/// The new iterator.
public IPointSetIterator CreatePointSetIterator(PointCloudFilter rFilter, double density, ElementId viewId)
{
throw new NotImplementedException();
}
///
/// The implementation of IPointCloudAccess.GetExtent().
///
/// The extents of the point cloud.
public Outline GetExtent()
{
return GetOutline();
}
///
/// The implementation of IPointCloudAccess.GetOffset().
///
/// This method is not used by Revit and will be removed in a later pre-release build.
/// Zero.
public XYZ GetOffset()
{
return XYZ.Zero;
}
///
/// The implementation of IPointCloudAccess.GetUnitsToFeetConversionFactor().
///
/// The scale.
public double GetUnitsToFeetConversionFactor()
{
return GetScale();
}
///
/// The implementation of IPointCloudAccess.ReadPoints().
///
/// The filter.
/// The view id (unused).
/// The point cloud buffer.
/// The maximum number of points.
/// The number of points read.
public int ReadPoints(PointCloudFilter rFilter, ElementId viewId, IntPtr buffer, int nBufferSize)
{
int read = ReadSomePoints(rFilter, buffer, nBufferSize, 0);
return read;
}
///
/// The implementation of IPointCloudAccess.Free().
///
public void Free()
{
}
#endregion
}
}