<commit_before>//
// BExtractorView.cpp : implementation of the BExtractorView class
//
// Copyright (c) 2001-2003 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

#include "StdAfx.h"
#include "BExtractor.h"

#include "BExtractorDoc.h"
#include "BExtractorView.h"
#include "FloodDialog.h"
#include "ConvolveDialog.h"
#include "KernelDialog.h"
#include "gdal_priv.h"
#include "BImage.h"
#include "Dib.h"
#include "ipl.h"			// Image Processing Library 2.1
#include "ProgDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//NOTE:
// The values below need to be selected very carefully (especially the ones
// expected to be the black pixels of the building) so that the total value
// obtained by the convolve2D function is approximately 255. That way, after
// the 8 bit shift is done, the pixel representing the center of a building
// will be black, all others (words, building edge pixels, etc) will have had
// their values reduced by not matching with n3, n1. Notice that if two
// buildings have less than two white pixels between them, they will also
// have their values reduced and will probably not show up in the final
// building count.
#define n3 -5
#define n1 -1
#define n2 10	//12 black pixels of this type in a perfect building
#define n4 15	// 9 black pixels of this type in a perfect building

#define SCROLL_RANGE	720
#define SCROLL_CENTER	360
#define SCROLL_MULT		50
/////////////////////////////////////////////////////////////////////////////
// BExtractorView

IMPLEMENT_DYNCREATE(BExtractorView, CView)

BEGIN_MESSAGE_MAP(BExtractorView, CView)
	//{{AFX_MSG_MAP(BExtractorView)
	ON_COMMAND(ID_COLORCHANGE, OnColorChange)
	ON_WM_HSCROLL()
	ON_WM_VSCROLL()
	ON_COMMAND(ID_FUNCTIONS_CONVOLVE, OnFunctionsConvolve)
	ON_COMMAND(ID_MODES_ADDREMOVE, OnAddRemove)
	ON_UPDATE_COMMAND_UI(ID_MODES_ADDREMOVE, OnUpdateAddRemove)
	ON_WM_LBUTTONUP()
	ON_COMMAND(ID_FULLRES, OnFullres)
	ON_COMMAND(ID_HAND, OnHand)
	ON_UPDATE_COMMAND_UI(ID_HAND, OnUpdateHand)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_COMMAND(ID_ZOOM_IN, OnZoomIn)
	ON_COMMAND(ID_ZOOM_OUT, OnZoomOut)
	ON_WM_MBUTTONUP()
	ON_WM_MBUTTONDOWN()
	ON_WM_KEYDOWN()
	ON_COMMAND(ID_CLEARSCREEN, OnClearscreenofBuildings)
	ON_COMMAND(ID_UNDO, OnUndo)
	ON_COMMAND(ID_VIEW_VIEWFULLCOLORIMAGE, OnViewViewfullcolorimage)
	ON_UPDATE_COMMAND_UI(ID_VIEW_VIEWFULLCOLORIMAGE, OnUpdateViewViewfullcolorimage)
	ON_COMMAND(ID_MODES_FOOTPRINT, OnModesFootprintMode)
	ON_UPDATE_COMMAND_UI(ID_MODES_FOOTPRINT, OnUpdateModesFootprintmode)
	ON_COMMAND(ID_MODES_RECTANGLE, OnModesRectangle)
	ON_UPDATE_COMMAND_UI(ID_MODES_RECTANGLE, OnUpdateModesRectangle)
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_MODES_CIRCLE, OnModesCircle)
	ON_UPDATE_COMMAND_UI(ID_MODES_CIRCLE, OnUpdateModesCircle)
	ON_UPDATE_COMMAND_UI(ID_UNDO, OnUpdateUndo)
	ON_UPDATE_COMMAND_UI(ID_FUNCTIONS_CONVOLVE, OnUpdateFunctionsConvolve)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
	ON_COMMAND(ID_MODES_MOVERESIZE, OnModesMoveresize)
	ON_UPDATE_COMMAND_UI(ID_MODES_MOVERESIZE, OnUpdateModesMoveresize)
	ON_COMMAND(ID_MODES_ROADNODE, OnModesRoadnode)
	ON_UPDATE_COMMAND_UI(ID_MODES_ROADNODE, OnUpdateModesRoadnode)
	ON_COMMAND(ID_CHANGE_ROAD_COLOR, OnChangeRoadColor)
	ON_COMMAND(ID_MODES_ROAD_EDIT, OnModesRoadEdit)
	ON_UPDATE_COMMAND_UI(ID_MODES_ROAD_EDIT, OnUpdateModesRoadEdit)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
// BExtractorView construction/destruction
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

BExtractorView::BExtractorView()
{
	m_offset.x = m_offset.y = 250;

	// initially 8 meters/pixel
	m_fScale = 8.0f;

	m_mode = LB_AddRemove;	//initially building select mode, not hand mode
	m_bPanning = false;
	m_iStep = 0;

	m_bRubber = false;
	m_maybeRect = false;

	m_zoomed = false;

	m_scrollposH = SCROLL_MULT;
	m_scrollposV = SCROLL_MULT;

	DWORD blah = MAX_PATH;
	GetCurrentDirectory(blah, m_directory);

	if (!ReadINIFile())
	{
		m_buildingColor = 0x0000ffff;
		m_roadColor = RGB(0xff, 0x00, 0x00);
	}
}

BExtractorView::~BExtractorView()
{
}

BOOL BExtractorView::PreCreateWindow(CREATESTRUCT& cs)
{
	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////////////<commit_msg>fixed VTST saving by adding the same structure defaults mechanism that VTBuilder uses<commit_after>//
// BExtractorView.cpp : implementation of the BExtractorView class
//
// Copyright (c) 2001-2003 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

#include "StdAfx.h"
#include "BExtractor.h"

#include "BExtractorDoc.h"
#include "BExtractorView.h"
#include "FloodDialog.h"
#include "ConvolveDialog.h"
#include "KernelDialog.h"
#include "gdal_priv.h"
#include "BImage.h"
#include "Dib.h"
#include "ipl.h"			// Image Processing Library 2.1
#include "ProgDlg.h"
#include <fstream>
#include "vtdata/FilePath.h"
#include "vtdata/vtLog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//NOTE:
// The values below need to be selected very carefully (especially the ones
// expected to be the black pixels of the building) so that the total value
// obtained by the convolve2D function is approximately 255. That way, after
// the 8 bit shift is done, the pixel representing the center of a building
// will be black, all others (words, building edge pixels, etc) will have had
// their values reduced by not matching with n3, n1. Notice that if two
// buildings have less than two white pixels between them, they will also
// have their values reduced and will probably not show up in the final
// building count.
#define n3 -5
#define n1 -1
#define n2 10	//12 black pixels of this type in a perfect building
#define n4 15	// 9 black pixels of this type in a perfect building

#define SCROLL_RANGE	720
#define SCROLL_CENTER	360
#define SCROLL_MULT		50
/////////////////////////////////////////////////////////////////////////////
// BExtractorView

IMPLEMENT_DYNCREATE(BExtractorView, CView)

BEGIN_MESSAGE_MAP(BExtractorView, CView)
	//{{AFX_MSG_MAP(BExtractorView)
	ON_COMMAND(ID_COLORCHANGE, OnColorChange)
	ON_WM_HSCROLL()
	ON_WM_VSCROLL()
	ON_COMMAND(ID_FUNCTIONS_CONVOLVE, OnFunctionsConvolve)
	ON_COMMAND(ID_MODES_ADDREMOVE, OnAddRemove)
	ON_UPDATE_COMMAND_UI(ID_MODES_ADDREMOVE, OnUpdateAddRemove)
	ON_WM_LBUTTONUP()
	ON_COMMAND(ID_FULLRES, OnFullres)
	ON_COMMAND(ID_HAND, OnHand)
	ON_UPDATE_COMMAND_UI(ID_HAND, OnUpdateHand)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_COMMAND(ID_ZOOM_IN, OnZoomIn)
	ON_COMMAND(ID_ZOOM_OUT, OnZoomOut)
	ON_WM_MBUTTONUP()
	ON_WM_MBUTTONDOWN()
	ON_WM_KEYDOWN()
	ON_COMMAND(ID_CLEARSCREEN, OnClearscreenofBuildings)
	ON_COMMAND(ID_UNDO, OnUndo)
	ON_COMMAND(ID_VIEW_VIEWFULLCOLORIMAGE, OnViewViewfullcolorimage)
	ON_UPDATE_COMMAND_UI(ID_VIEW_VIEWFULLCOLORIMAGE, OnUpdateViewViewfullcolorimage)
	ON_COMMAND(ID_MODES_FOOTPRINT, OnModesFootprintMode)
	ON_UPDATE_COMMAND_UI(ID_MODES_FOOTPRINT, OnUpdateModesFootprintmode)
	ON_COMMAND(ID_MODES_RECTANGLE, OnModesRectangle)
	ON_UPDATE_COMMAND_UI(ID_MODES_RECTANGLE, OnUpdateModesRectangle)
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_MODES_CIRCLE, OnModesCircle)
	ON_UPDATE_COMMAND_UI(ID_MODES_CIRCLE, OnUpdateModesCircle)
	ON_UPDATE_COMMAND_UI(ID_UNDO, OnUpdateUndo)
	ON_UPDATE_COMMAND_UI(ID_FUNCTIONS_CONVOLVE, OnUpdateFunctionsConvolve)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
	ON_COMMAND(ID_MODES_MOVERESIZE, OnModesMoveresize)
	ON_UPDATE_COMMAND_UI(ID_MODES_MOVERESIZE, OnUpdateModesMoveresize)
	ON_COMMAND(ID_MODES_ROADNODE, OnModesRoadnode)
	ON_UPDATE_COMMAND_UI(ID_MODES_ROADNODE, OnUpdateModesRoadnode)
	ON_COMMAND(ID_CHANGE_ROAD_COLOR, OnChangeRoadColor)
	ON_COMMAND(ID_MODES_ROAD_EDIT, OnModesRoadEdit)
	ON_UPDATE_COMMAND_UI(ID_MODES_ROAD_EDIT, OnUpdateModesRoadEdit)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
// BExtractorView construction/destruction
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

BExtractorView::BExtractorView()
{
	m_offset.x = m_offset.y = 250;

	// initially 8 meters/pixel
	m_fScale = 8.0f;

	m_mode = LB_AddRemove;	//initially building select mode, not hand mode
	m_bPanning = false;
	m_iStep = 0;

	m_bRubber = false;
	m_maybeRect = false;

	m_zoomed = false;

	m_scrollposH = SCROLL_MULT;
	m_scrollposV = SCROLL_MULT;

	DWORD blah = MAX_PATH;
	GetCurrentDirectory(blah, m_directory);

	if (!ReadINIFile())
	{
		m_buildingColor = 0x0000ffff;
		m_roadColor = RGB(0xff, 0x00, 0x00);
	}

	// Load structure defaults
	vtStringArray paths;
	ReadEnviroPaths(paths);
	LoadGlobalMaterials(paths);
	SetupDefaultStructures();
}

BExtractorView::~BExtractorView()
{
}

BOOL BExtractorView::PreCreateWindow(CREATESTRUCT& cs)
{
	return CView::PreCreateWindow(cs);
}

//////////////////////////////

using namespace std;

#define STR_DATAPATH "DataPath"

void BExtractorView::ReadEnviroPaths(vtStringArray &paths)
{
	ifstream input;
	input.open("Enviro.ini", ios::in | ios::binary);
	if (!input.is_open())
	{
		input.clear();
		input.open("../Enviro/Enviro.ini", ios::in | ios::binary);
	}
	if (!input.is_open())
		return;

	char buf[80];
	while (!input.eof())
	{
		if (input.peek() == '\n')
			input.ignore();
		input >> buf;

		// data value should been separated by a tab or space
		int next = input.peek();
		if (next != '\t' && next != ' ')
			continue;
		while (input.peek() == '\t' || input.peek() == ' ')
			input.ignore();

		if (strcmp(buf, STR_DATAPATH) == 0)
		{
			vtString string = get_line_from_stream(input);
			paths.push_back(vtString(string));
		}
	}
	VTLOG("Datapaths:\n");
	int i, n = paths.size();
	if (n == 0)
		VTLOG("   none.\n");
	for (i = 0; i < n; i++)
	{
		VTLOG("   %s\n", (const char *) paths[i]);
	}
}


/////////////////////////////////////////////////////////////////////////////////////
{'fraction_non_alphanumeric': 0.1824953445065177, 'fraction_numerical': 0.011080074487895717, 'mean_word_length': 3.454997926171713, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1446335', 'n_tokens_mistral': 3833, 'n_tokens_neox': 3735, 'n_words': 799}