<commit_before>/* medClutEditor.cpp ---
 *
 * Author: <NAME>
 * Copyright (C) 2008 - <NAME>, Inria.
 * Created: Tue May  5 12:20:38 2009 (+0200)
 * Version: $Id$
 * Last-Updated: Tue Feb  9 23:11:38 2010 (+0100)
 *           By: <NAME>
 *     Update #: 274
 */

/* Commentary:
 *
 */

/* Change log:
 *
 */

#include <dtkCore/dtkAbstractData.h>
#include <dtkCore/dtkAbstractDataImage.h>
#include <dtkCore/dtkAbstractView.h>
#include <medCore/medAbstractView.h>
#include <medCore/medStorage.h>
#include "medClutEditor.h"

#include <math.h>
#include <limits>

#include "medLUTtoXMLWriter.h"
#include "medXMLtoLUTReader.h"
#include "medSaveLUTDialog.h"
#include "medLoadLUTDialog.h"

// /////////////////////////////////////////////////////////////////
// medClutEditorVertex
// /////////////////////////////////////////////////////////////////

class medClutEditorVertexPrivate
{
public:
    QPointF value;
    QColor color;

    QColor fgColor;
    QColor bgColor;

    qreal innerRadius;
    qreal outerRadius;

    bool isMoved;
    QPointF lastPos;
};

medClutEditorVertex::medClutEditorVertex(QPointF value, QPointF coord,
					 QColor color, QGraphicsItem * parent)
  : QGraphicsItem(parent)
{
    d = new medClutEditorVertexPrivate;
    d->value = value;
    this->setPos( coord );
    // if ( medClutEditorScene * scene =
    // 	 dynamic_cast< medClutEditorScene * >( this->scene() ) )
    // 	d->value = scene->coordinateToValue( this->pos() );
    this->setZValue(1);
    d->innerRadius =  5.0;
    d->outerRadius = 10.0;

    setAlpha();
    setColor( color );

    d->isMoved = false;

    this->setFlag(QGraphicsItem::ItemIsMovable, true);
    this->setFlag(QGraphicsItem::ItemIsSelectable, true);
}

medClutEditorVertex::medClutEditorVertex( const medClutEditorVertex & other,
					  QGraphicsItem * parent)
  : QGraphicsItem( parent )
{
    if ( parent == NULL )
	this->setParentItem( other.parentItem() );
    
    d = new medClutEditorVertexPrivate;
    d->value = other.d->value;
    d->color   = other.d->color;
    d->fgColor = other.d->fgColor;
    d->bgColor = other.d->bgColor;
    d->innerRadius = other.d->innerRadius;
    d->outerRadius = other.d->outerRadius;

    this->setPos( other.pos() );
    this->setZValue(1);
    setAlpha();
    setColor( d->color );

    this->setFlag(QGraphicsItem::ItemIsMovable, true);
    this->setFlag(QGraphicsItem::ItemIsSelectable, true);
}

medClutEditorVertex::~medClutEditorVertex(void)
{
    delete d;
}

const QPointF & medClutEditorVertex::value() const
{
    return d->value;
}

void medClutEditorVertex::shiftValue( qreal amount, bool forceConstraints )
{
    if ( amount != 0.0 ) {
	medClutEditorTable * table =
	    dynamic_cast< medClutEditorTable * >( this->parentItem() );
	forceConstraints = forceConstraints && table;

	if ( forceConstraints )
	    table->initiateMoveSelection();
	this->setX( this->x() + amount );
	if ( forceConstraints ) {
	    table->constrainMoveSelection( this );
	    table->finalizeMoveSelection();
	}

        this->updateValue();
    }
}

void medClutEditorVertex::interpolate( medClutEditorVertex * prev,
                                       medClutEditorVertex * next )
{
  if ( prev != NULL && next == NULL )
      setColor( prev->color() );
  else if ( prev == NULL && next != NULL )
      setColor( next->color() );
  else if ( prev != NULL && next != NULL ) {
      if ( ( prev->color().alpha() == 0 ) &&
           ( next->color().alpha() > 0 ) )
          setColor( next->color() );
      else if ( ( prev->color().alpha() > 0 ) &&
                ( next->color().alpha() == 0 ) )
          setColor( prev->color() );
      else if ( ( this->x() - prev->x() ) < ( next->x() - this->x() ) )
          setColor( prev->color() );
      else<commit_msg>fixes bug when windowing in TF editor<commit_after>/* medClutEditor.cpp ---
 *
 * Author: <NAME>
 * Copyright (C) 2008 - <NAME>, Inria.
 * Created: Tue May  5 12:20:38 2009 (+0200)
 * Version: $Id$
 * Last-Updated: Tue Feb  9 23:11:38 2010 (+0100)
 *           By: <NAME>
 *     Update #: 274
 */

/* Commentary:
 *
 */

/* Change log:
 *
 */

#include <dtkCore/dtkAbstractData.h>
#include <dtkCore/dtkAbstractDataImage.h>
#include <dtkCore/dtkAbstractView.h>
#include <medCore/medAbstractView.h>
#include <medCore/medStorage.h>
#include "medClutEditor.h"

#include <math.h>
#include <limits>

#include "medLUTtoXMLWriter.h"
#include "medXMLtoLUTReader.h"
#include "medSaveLUTDialog.h"
#include "medLoadLUTDialog.h"

// /////////////////////////////////////////////////////////////////
// medClutEditorVertex
// /////////////////////////////////////////////////////////////////

class medClutEditorVertexPrivate
{
public:
    QPointF value;
    QColor color;

    QColor fgColor;
    QColor bgColor;

    qreal innerRadius;
    qreal outerRadius;

    bool isMoved;
    QPointF lastPos;
};

medClutEditorVertex::medClutEditorVertex(QPointF value, QPointF coord,
					 QColor color, QGraphicsItem * parent)
  : QGraphicsItem(parent)
{
    d = new medClutEditorVertexPrivate;
    d->value = value;
    this->setPos( coord );
    // if ( medClutEditorScene * scene =
    // 	 dynamic_cast< medClutEditorScene * >( this->scene() ) )
    // 	d->value = scene->coordinateToValue( this->pos() );
    this->setZValue(1);
    d->innerRadius =  5.0;
    d->outerRadius = 10.0;

    setAlpha();
    setColor( color );

    d->isMoved = false;

    this->setFlag(QGraphicsItem::ItemIsMovable, true);
    this->setFlag(QGraphicsItem::ItemIsSelectable, true);
}

medClutEditorVertex::medClutEditorVertex( const medClutEditorVertex & other,
					  QGraphicsItem * parent)
  : QGraphicsItem( parent )
{
    if ( parent == NULL )
	this->setParentItem( other.parentItem() );
    
    d = new medClutEditorVertexPrivate;
    d->value = other.d->value;
    d->color   = other.d->color;
    d->fgColor = other.d->fgColor;
    d->bgColor = other.d->bgColor;
    d->innerRadius = other.d->innerRadius;
    d->outerRadius = other.d->outerRadius;

    this->setPos( other.pos() );
    this->setZValue(1);
    setAlpha();
    setColor( d->color );

    this->setFlag(QGraphicsItem::ItemIsMovable, true);
    this->setFlag(QGraphicsItem::ItemIsSelectable, true);
}

medClutEditorVertex::~medClutEditorVertex(void)
{
    delete d;
}

const QPointF & medClutEditorVertex::value() const
{
    return d->value;
}

void medClutEditorVertex::shiftValue( qreal amount, bool forceConstraints )
{
    if ( amount != 0.0 ) {

	medClutEditorTable * table =
	    dynamic_cast< medClutEditorTable * >( this->parentItem() );
	forceConstraints = forceConstraints && table;

	medClutEditorScene * scene =
	    dynamic_cast< medClutEditorScene * >( this->scene() );
	QPointF value = d->value;
	value.setX( value.x() + amount );

	if ( forceConstraints )
	    table->initiateMoveSelection();
	this->setPos( scene->valueToCoordinate( value ) );
	if ( forceConstraints ) {
	    table->constrainMoveSelection( this );
	    table->finalizeMoveSelection();
	}

        this->updateValue();
    }
}

void medClutEditorVertex::interpolate( medClutEditorVertex * prev,
                                       medClutEditorVertex * next )
{
  if ( prev != NULL && next == NULL )
      setColor( prev->color() );
  else if ( prev == NULL && next != NULL )
      setColor( next->color() );
  else if ( prev != NULL && next != NULL ) {
      if ( ( prev->color().alpha() == 0 ) &&
           ( next->color().alpha() > 0 ) )
          setColor( next->color() );
      else if ( ( prev->color().alpha() > 0 ) &&
                ( next->color().alpha() == 0 ) )
          setColor( prev->color() );
      else if ( ( this->x() - prev->x() ) < ( next->x() - this->x() ) )
          setColor( prev->color() );
      else
{'fraction_non_alphanumeric': 0.1817592952454981, 'fraction_numerical': 0.012955045990413265, 'mean_word_length': 2.6380772855796417, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 136, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '898599', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2511, 'n_words': 500}