<commit_before>// @(#)root/eve7:$Id$
// Authors: <NAME> & <NAME>: 2006, 2007

/*************************************************************************
 * Copyright (C) 1995-2019, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include <ROOT/REveStraightLineSet.hxx>
#include <ROOT/REveRenderData.hxx>
#include <ROOT/REveProjectionManager.hxx>

#include "TRandom.h"
#include "TClass.h"
#include "json.hpp"

using namespace ROOT::Experimental;

////////////////////////////////////////////////////////////////////////////////
/// Constructor.

REveStraightLineSet::REveStraightLineSet(const std::string& n, const std::string& t):
   REveElement (n, t),

   fLinePlex      (sizeof(Line_t), 4),
   fMarkerPlex    (sizeof(Marker_t), 8),
   fOwnLinesIds   (kFALSE),
   fOwnMarkersIds (kFALSE),
   fRnrMarkers    (kTRUE),
   fRnrLines      (kTRUE),
   fDepthTest     (kTRUE),
   fLastLine      (0)
{
   InitMainTrans();
   fPickable = kTRUE;

   fMainColorPtr = &fLineColor;
   fLineColor    = 4;
   fMarkerColor  = 2;
   fMarkerStyle  = 20;
}

////////////////////////////////////////////////////////////////////////////////
/// Add a line.

REveStraightLineSet::Line_t*
REveStraightLineSet::AddLine(Float_t x1, Float_t y1, Float_t z1,
                             Float_t x2, Float_t y2, Float_t z2)
{
   fLastLine = new (fLinePlex.NewAtom()) Line_t(x1, y1, z1, x2, y2, z2);
   fLastLine->fId = fLinePlex.Size() - 1;
   return fLastLine;
}

////////////////////////////////////////////////////////////////////////////////
/// Add a line.

REveStraightLineSet::Line_t*
REveStraightLineSet::AddLine(const REveVector& p1, const REveVector& p2)
{
   return AddLine(p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
}

////////////////////////////////////////////////////////////////////////////////
/// Set line vertices with given index.

void
REveStraightLineSet::SetLine(int idx,
                             Float_t x1, Float_t y1, Float_t z1,
                             Float_t x2, Float_t y2, Float_t z2)
{
   Line_t* l = (Line_t*) fLinePlex.Atom(idx);

   l->fV1[0] = x1; l->fV1[1] = y1; l->fV1[2] = z1;
   l->fV2[0] = x2; l->fV2[1] = y2; l->fV2[2] = z2;
}

////////////////////////////////////////////////////////////////////////////////
/// Set line vertices with given index.

void
REveStraightLineSet::SetLine(int idx, const REveVector& p1, const REveVector& p2)
{
   SetLine(idx, p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
}

////////////////////////////////////////////////////////////////////////////////
/// Add a marker with given position.

REveStraightLineSet::Marker_t*
REveStraightLineSet::AddMarker(Float_t x, Float_t y, Float_t z, Int_t line_id)
{
   Marker_t* marker = new (fMarkerPlex.NewAtom()) Marker_t(x, y, z, line_id);
   return marker;
}

////////////////////////////////////////////////////////////////////////////////
/// Add a marker with given position.

REveStraightLineSet::Marker_t*
REveStraightLineSet::AddMarker(const REveVector& p, Int_t line_id)
{
   return AddMarker(p.fX, p.fY, p.fZ, line_id);
}

////////////////////////////////////////////////////////////////////////////////
/// Add a marker for line with given index on relative position pos.

REveStraightLineSet::Marker_t*
REveStraightLineSet::AddMarker(Int_t line_id, Float_t pos)
{
   Line_t& l = * (Line_t*) fLinePlex.Atom(line_id);
   return AddMarker(l.fV1[0] + (l.fV2[0] - l.fV1[0])*pos,
                    l.fV1[1] + (l.fV2[1] - l.fV1[1])*pos,
                    l.fV1[2] + (l.fV2[2] - l.fV1[2])*pos,
                    line_id);
}

////////////////////////////////////////////////////////////////////////////////
/// Copy visualization parameters from element el.

void REveStraightLineSet::CopyVizParams(const REveElement* el)
{
   const REveStraightLineSet* m = dynamic_cast<const REveStraightLineSet*>(el);
   if (m)
   {
      TAttLine::operator=(*m);
      TAttMarker::operator=(*m);
      fRnrMarkers = m->fRnrMarkers;
      fRnrLines   = m->fRnrLines;
      fDepthTest  = m->fDepthTest;
   }

   REveElement::CopyVizParams(el);
}

////////////////////////////////////////////////////////////////////////////////
/// Write visualization parameters.

void REveStraightLineSet::WriteVizParams(std::ostream& out, const TString& var)
{
   REveElement::WriteVizParams(out, var);

   TString t = "   " + var + "->";
   TAttMarker::SaveMarkerAttributes(out, var);
   TAttLine  ::SaveLineAttributes  (out, var);
   out << t << "SetRnrMarkers(" << ToString(fRnrMarkers) << ");\n";
   out << t << "SetRnrLines("   << ToString(fRnrLines)   << ");\n";
   out << t << "SetDepthTest("  << ToString(fDepthTest)  << ");\n";
}

////////////////////////////////////////////////////////////////////////////////
/// Fill core part of JSON representation.

Int_t REveStraightLineSet::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
{
   Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);

   j["fLinePlexSize"] = fLinePlex.Size();
   j["fMarkerPlexSize"] = fMarkerPlex.Size();
   printf("REveStraightLineSet::WriteCoreJson %d \n", ret);
   return ret;
}

////////////////////////////////////////////////////////////////////////////////
/// Crates 3D point array for rendering.

void REveStraightLineSet::BuildRenderData()
{
   int nVertices =  fLinePlex.Size() * 2 + fMarkerPlex.Size();
   fRenderData = std::make_unique<REveRenderData>("makeStraightLineSet", 3 * nVertices, 0, nVertices);

   printf("REveStraightLineSet::BuildRenderData id = %d \n", GetElementId());
   REveChunkManager::iterator li(fLinePlex);
   while (li.next()) {
      Line_t* l = (Line_t*)li();

      fRenderData->PushV(l->fV1[0], l->fV1[1],l->fV1[2]);
      fRenderData->PushV(l->fV2[0], l->fV2[1],l->fV2[2]);
      fRenderData->PushI(l->fId);
   }<commit_msg>stream line attributes<commit_after>// @(#)root/eve7:$Id$
// Authors: <NAME> & <NAME>: 2006, 2007

/*************************************************************************
 * Copyright (C) 1995-2019, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include <ROOT/REveStraightLineSet.hxx>
#include <ROOT/REveRenderData.hxx>
#include <ROOT/REveProjectionManager.hxx>

#include "TRandom.h"
#include "TClass.h"
#include "json.hpp"

using namespace ROOT::Experimental;

////////////////////////////////////////////////////////////////////////////////
/// Constructor.

REveStraightLineSet::REveStraightLineSet(const std::string& n, const std::string& t):
   REveElement (n, t),

   fLinePlex      (sizeof(Line_t), 4),
   fMarkerPlex    (sizeof(Marker_t), 8),
   fOwnLinesIds   (kFALSE),
   fOwnMarkersIds (kFALSE),
   fRnrMarkers    (kTRUE),
   fRnrLines      (kTRUE),
   fDepthTest     (kTRUE),
   fLastLine      (0)
{
   InitMainTrans();
   fPickable = kTRUE;

   fMainColorPtr = &fLineColor;
   fLineColor    = 4;
   fMarkerColor  = 2;
   fMarkerStyle  = 20;
}

////////////////////////////////////////////////////////////////////////////////
/// Add a line.

REveStraightLineSet::Line_t*
REveStraightLineSet::AddLine(Float_t x1, Float_t y1, Float_t z1,
                             Float_t x2, Float_t y2, Float_t z2)
{
   fLastLine = new (fLinePlex.NewAtom()) Line_t(x1, y1, z1, x2, y2, z2);
   fLastLine->fId = fLinePlex.Size() - 1;
   return fLastLine;
}

////////////////////////////////////////////////////////////////////////////////
/// Add a line.

REveStraightLineSet::Line_t*
REveStraightLineSet::AddLine(const REveVector& p1, const REveVector& p2)
{
   return AddLine(p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
}

////////////////////////////////////////////////////////////////////////////////
/// Set line vertices with given index.

void
REveStraightLineSet::SetLine(int idx,
                             Float_t x1, Float_t y1, Float_t z1,
                             Float_t x2, Float_t y2, Float_t z2)
{
   Line_t* l = (Line_t*) fLinePlex.Atom(idx);

   l->fV1[0] = x1; l->fV1[1] = y1; l->fV1[2] = z1;
   l->fV2[0] = x2; l->fV2[1] = y2; l->fV2[2] = z2;
}

////////////////////////////////////////////////////////////////////////////////
/// Set line vertices with given index.

void
REveStraightLineSet::SetLine(int idx, const REveVector& p1, const REveVector& p2)
{
   SetLine(idx, p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
}

////////////////////////////////////////////////////////////////////////////////
/// Add a marker with given position.

REveStraightLineSet::Marker_t*
REveStraightLineSet::AddMarker(Float_t x, Float_t y, Float_t z, Int_t line_id)
{
   Marker_t* marker = new (fMarkerPlex.NewAtom()) Marker_t(x, y, z, line_id);
   return marker;
}

////////////////////////////////////////////////////////////////////////////////
/// Add a marker with given position.

REveStraightLineSet::Marker_t*
REveStraightLineSet::AddMarker(const REveVector& p, Int_t line_id)
{
   return AddMarker(p.fX, p.fY, p.fZ, line_id);
}

////////////////////////////////////////////////////////////////////////////////
/// Add a marker for line with given index on relative position pos.

REveStraightLineSet::Marker_t*
REveStraightLineSet::AddMarker(Int_t line_id, Float_t pos)
{
   Line_t& l = * (Line_t*) fLinePlex.Atom(line_id);
   return AddMarker(l.fV1[0] + (l.fV2[0] - l.fV1[0])*pos,
                    l.fV1[1] + (l.fV2[1] - l.fV1[1])*pos,
                    l.fV1[2] + (l.fV2[2] - l.fV1[2])*pos,
                    line_id);
}

////////////////////////////////////////////////////////////////////////////////
/// Copy visualization parameters from element el.

void REveStraightLineSet::CopyVizParams(const REveElement* el)
{
   const REveStraightLineSet* m = dynamic_cast<const REveStraightLineSet*>(el);
   if (m)
   {
      TAttLine::operator=(*m);
      TAttMarker::operator=(*m);
      fRnrMarkers = m->fRnrMarkers;
      fRnrLines   = m->fRnrLines;
      fDepthTest  = m->fDepthTest;
   }

   REveElement::CopyVizParams(el);
}

////////////////////////////////////////////////////////////////////////////////
/// Write visualization parameters.

void REveStraightLineSet::WriteVizParams(std::ostream& out, const TString& var)
{
   REveElement::WriteVizParams(out, var);

   TString t = "   " + var + "->";
   TAttMarker::SaveMarkerAttributes(out, var);
   TAttLine  ::SaveLineAttributes  (out, var);
   out << t << "SetRnrMarkers(" << ToString(fRnrMarkers) << ");\n";
   out << t << "SetRnrLines("   << ToString(fRnrLines)   << ");\n";
   out << t << "SetDepthTest("  << ToString(fDepthTest)  << ");\n";
}

////////////////////////////////////////////////////////////////////////////////
/// Fill core part of JSON representation.

Int_t REveStraightLineSet::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
{
   Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);

   j["fLinePlexSize"] = fLinePlex.Size();
   j["fMarkerPlexSize"] = fMarkerPlex.Size();
   j["fLineWidth"] = fLineWidth;
   j["fLineStyle"] = fLineStyle;
   j["fMarkerSize"] = fMarkerSize;
   j["fMarkerStyle"] = fMarkerStyle;
   printf("REveStraightLineSet::WriteCoreJson %d \n", ret);
   return ret;
}

////////////////////////////////////////////////////////////////////////////////
/// Crates 3D point array for rendering.

void REveStraightLineSet::BuildRenderData()
{
   int nVertices =  fLinePlex.Size() * 2 + fMarkerPlex.Size();
   fRenderData = std::make_unique<REveRenderData>("makeStraightLineSet", 3 * nVertices, 0, nVertices);

   printf("REveStraightLineSet::BuildRenderData id = %d \n", GetElementId());
   REveChunkManager::iterator li(fLinePlex);
   while (li.next()) {
      Line_t* l = (Line_t*)li();

      fRenderData->PushV(l->fV1[0], l->fV1[1],l->fV1[2]);
      fRenderData->PushV(l->fV2[0], l->fV2[1],l->fV2[2]);
      fRenderData->PushI(l->fId);
   }
{'fraction_non_alphanumeric': 0.3028140459005758, 'fraction_numerical': 0.018003406049793204, 'mean_word_length': 1.7706133453156594, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4997600', 'n_tokens_mistral': 4151, 'n_tokens_neox': 3977, 'n_words': 780}