view Framework/Toolbox/DicomStructureSet.h @ 124:5099aaa53bd0 wasm

removal of OrthancSeriesLoader
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 08 Oct 2017 10:52:24 +0200
parents e3433dabfb8d
children 44fc253d4876
line wrap: on
line source

/**
 * Stone of Orthanc
 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
 * Department, University Hospital of Liege, Belgium
 * Copyright (C) 2017 Osimis, Belgium
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 **/


#pragma once

#include "CoordinateSystem3D.h"
#include "../Viewport/CairoContext.h"

#include <Plugins/Samples/Common/FullOrthancDataset.h>

#include <list>

namespace OrthancStone
{
  class DicomStructureSet : public boost::noncopyable
  {
  private:
    struct ReferencedSlice
    {
      std::string          seriesInstanceUid_;
      CoordinateSystem3D   geometry_;
      double               thickness_;

      ReferencedSlice()
      {
      }
      
      ReferencedSlice(const std::string& seriesInstanceUid,
                      const CoordinateSystem3D& geometry,
                      double thickness) :
        seriesInstanceUid_(seriesInstanceUid),
        geometry_(geometry),
        thickness_(thickness)
      {
      }
    };

    typedef std::map<std::string, ReferencedSlice>  ReferencedSlices;
    
    typedef std::list<Vector>  Points;

    class Polygon
    {
    private:
      std::string sopInstanceUid_;
      bool        hasSlice_;
      Vector      normal_;
      double      projectionAlongNormal_;
      double      sliceThickness_;  // In millimeters
      Points      points_;

      void CheckPoint(const Vector& v);

    public:
      Polygon(const std::string& sopInstanceUid) :
        sopInstanceUid_(sopInstanceUid),
        hasSlice_(false)
      {
      }

      void AddPoint(const Vector& v);

      bool UpdateReferencedSlice(const ReferencedSlices& slices);

      bool IsOnSlice(const CoordinateSystem3D& geometry) const;

      const std::string& GetSopInstanceUid() const
      {
        return sopInstanceUid_;
      }

      const Points& GetPoints() const
      {
        return points_;
      }
    };

    typedef std::list<Polygon>  Polygons;

    struct Structure
    {
      std::string   name_;
      std::string   interpretation_;
      Polygons      polygons_;
      uint8_t       red_;
      uint8_t       green_;
      uint8_t       blue_;
    };

    typedef std::vector<Structure>  Structures;

    Structures        structures_;
    ReferencedSlices  referencedSlices_;

    const Structure& GetStructure(size_t index) const;

  public:
    DicomStructureSet(const OrthancPlugins::FullOrthancDataset& instance);

    size_t GetStructureCount() const
    {
      return structures_.size();
    }

    Vector GetStructureCenter(size_t index) const;

    const std::string& GetStructureName(size_t index) const;

    const std::string& GetStructureInterpretation(size_t index) const;

    void GetStructureColor(uint8_t& red,
                           uint8_t& green,
                           uint8_t& blue,
                           size_t index) const;

    void GetReferencedInstances(std::set<std::string>& instances);

    void AddReferencedSlice(const std::string& sopInstanceUid,
                            const std::string& seriesInstanceUid,
                            const CoordinateSystem3D& geometry,
                            double thickness);

    void AddReferencedSlice(const Orthanc::DicomMap& dataset);

    void CheckReferencedSlices();

    void Render(CairoContext& context,
                const CoordinateSystem3D& slice);

    Vector GetNormal() const;

    static DicomStructureSet* SynchronousLoad(OrthancPlugins::IOrthancConnection& orthanc,
                                              const std::string& instanceId);
  };
}